From 27c1b5b9a5cadf1d1331e4cefeaa9c8a73707b26 Mon Sep 17 00:00:00 2001 From: talha Date: Sun, 19 Nov 2023 15:05:03 +0500 Subject: Added harpoon --- after/plugin/harpoon.lua | 10 ++++++++ after/plugin/lsp.lua | 14 ++++++++--- init.lua | 2 +- lua/linux/functions.lua | 62 ---------------------------------------------- lua/linux/init.lua | 4 --- lua/linux/packer.lua | 41 ------------------------------ lua/linux/remap.lua | 35 -------------------------- lua/linux/set.lua | 36 --------------------------- lua/talha/functions.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++++ lua/talha/init.lua | 4 +++ lua/talha/packer.lua | 40 ++++++++++++++++++++++++++++++ lua/talha/remap.lua | 37 +++++++++++++++++++++++++++ lua/talha/set.lua | 36 +++++++++++++++++++++++++++ plugin/packer_compiled.lua | 19 ++++++++------ 14 files changed, 213 insertions(+), 189 deletions(-) create mode 100644 after/plugin/harpoon.lua delete mode 100644 lua/linux/functions.lua delete mode 100644 lua/linux/init.lua delete mode 100644 lua/linux/packer.lua delete mode 100644 lua/linux/remap.lua delete mode 100644 lua/linux/set.lua create mode 100644 lua/talha/functions.lua create mode 100644 lua/talha/init.lua create mode 100644 lua/talha/packer.lua create mode 100644 lua/talha/remap.lua create mode 100644 lua/talha/set.lua diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua new file mode 100644 index 0000000..7d2a7a6 --- /dev/null +++ b/after/plugin/harpoon.lua @@ -0,0 +1,10 @@ +local mark = require("harpoon.mark") +local ui = require("harpoon.ui") + +vim.keymap.set("n", "a", mark.add_file) +vim.keymap.set("n", "", ui.toggle_quick_menu) + +vim.keymap.set("n", "y", function() ui.nav_file(1) end) +vim.keymap.set("n", "u", function() ui.nav_file(2) end) +vim.keymap.set("n", "i", function() ui.nav_file(3) end) +vim.keymap.set("n", "o", function() ui.nav_file(4) end) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 0bc840d..f8dae3c 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -9,9 +9,17 @@ end lsp.on_attach(function(client, bufnr) -- see :help lsp-zero-keybindings -- to learn the available actions - lsp.default_keymaps({buffer = bufnr}) - - local opts = {buffer = bufnr} + local opts = {buffer = bufnr, remap = false} + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) end) lsp.setup() diff --git a/init.lua b/init.lua index d738e2e..1105fe8 100644 --- a/init.lua +++ b/init.lua @@ -1 +1 @@ -require("linux") +require("talha") diff --git a/lua/linux/functions.lua b/lua/linux/functions.lua deleted file mode 100644 index 946bfd8..0000000 --- a/lua/linux/functions.lua +++ /dev/null @@ -1,62 +0,0 @@ -local Path = require"plenary.path" - -function CreateDailyNote() - local file_path = vim.api.nvim_buf_get_name(0) - local dir_path = file_path - local path_obj = Path:new(file_path) - - if path_obj:is_file() == true then - path_obj = path_obj:parent() -- get the parent directory - dir_path = path_obj:_fs_filename() - end - - local today_date_fmt = os.date('%Y-%m-%d') - local daily_note_file_name = today_date_fmt .. '.md' - local daily_note_file_obj = path_obj:joinpath(daily_note_file_name) - - local template_file_name = '.daily-notes-template.md' - local template_file_obj = path_obj:joinpath(template_file_name) - - local status = template_file_obj:copy({destination=daily_note_file_obj}) - - -- check if operation was a success - if status[daily_note_file_obj] == false then - print('Error! failed to create daily note') - print([[Possible Causes: - 1. No `.daily-notes-template.md` found - 2. Something went wrong with copy, in which case check nvim config]]) - return - end - - vim.cmd('e ' .. daily_note_file_obj:_fs_filename()) -end - -local function _ReloadConfigsInPath(path_selector) - local config_paths = vim.fn.glob(path_selector, true, true) - - for _, filepath in ipairs(config_paths) do - dofile(filepath) - end -end - -function ReloadLuaConfig() - for name,_ in pairs(package.loaded) do - if name:match('^linux') then - package.loaded[name] = nil - end - end - - -- Reload init/ directory - local lua_path_selector = vim.fn.stdpath('config') .. '/lua/**/*.lua' - _ReloadConfigsInPath(lua_path_selector) - - -- local after_path_selector = vim.fn.stdpath('config') .. '/after/**/*.lua' - _ReloadConfigsInPath(after_path_selector) - - print('Nvim configurations reloaded') -end - -function ToggleSpellCheck() - vim.opt.spell = not(vim.opt.spell:get()) - vim.opt.spelllang = 'en_us' -end diff --git a/lua/linux/init.lua b/lua/linux/init.lua deleted file mode 100644 index 0fbdc54..0000000 --- a/lua/linux/init.lua +++ /dev/null @@ -1,4 +0,0 @@ -require("linux.remap") -require("linux.set") -require("linux.functions") - diff --git a/lua/linux/packer.lua b/lua/linux/packer.lua deleted file mode 100644 index 704531a..0000000 --- a/lua/linux/packer.lua +++ /dev/null @@ -1,41 +0,0 @@ --- TODO: add formatter -vim.cmd [[packadd packer.nvim]] - -return require('packer').startup(function(use) - -- Packer can manage itself - use 'wbthomason/packer.nvim' - - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.2', - -- or , branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} } - } - - - use({ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }) - - -- colorschemes - use { "ellisonleao/gruvbox.nvim" } - use { "huyvohcmc/atlas.vim" } - use { "yorickpeterse/vim-paper" } - - use('mbbill/undotree') - - use('tpope/vim-fugitive') - - use { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v2.x', - requires = { - -- LSP Support - {'neovim/nvim-lspconfig'}, -- Required - {'williamboman/mason.nvim'}, -- Optional - {'williamboman/mason-lspconfig.nvim'}, -- Optional - - -- Autocompletion - {'hrsh7th/nvim-cmp'}, -- Required - {'hrsh7th/cmp-nvim-lsp'}, -- Required - {'L3MON4D3/LuaSnip'}, -- Required - } - } -end) diff --git a/lua/linux/remap.lua b/lua/linux/remap.lua deleted file mode 100644 index dfc7aca..0000000 --- a/lua/linux/remap.lua +++ /dev/null @@ -1,35 +0,0 @@ -vim.g.mapleader = " " - --- open project view with netrw -vim.keymap.set("n", "pv", vim.cmd.Ex) - --- file splitting -vim.keymap.set("n", "vs", vim.cmd.vsplit) -vim.keymap.set("n", "hs", vim.cmd.split) - --- moving selected lines across lines -vim.keymap.set("v", "J", ":m '>+1gv=gv") -vim.keymap.set("v", "K", ":m '<-2gv=gv") - --- not moving cursor when bringing files up -vim.keymap.set("n", "J", "mzJ`z") - --- keep cursor in screen center when moving up and down -vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "", "zz") - --- keep cursor in screen center when traversing in find -vim.keymap.set("n", "n", "nzzzv") -vim.keymap.set("n", "N", "Nzzzv") - --- copying to system clipboard -vim.keymap.set("n", "y", [["+y]]) -vim.keymap.set("v", "y", [["+y]]) -vim.keymap.set("n", "Y", [["+Y]]) - --- deleting without polluting vim clipboard -vim.keymap.set("n", "d", [["_d]]) -vim.keymap.set("v", "d", [["_d]]) - --- global substitute the word cursor is on in current file -vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) diff --git a/lua/linux/set.lua b/lua/linux/set.lua deleted file mode 100644 index 0366b03..0000000 --- a/lua/linux/set.lua +++ /dev/null @@ -1,36 +0,0 @@ -local op = vim.opt - -op.nu = true -op.relativenumber = true - -op.tabstop = 2 -op.softtabstop = 2 -op.shiftwidth = 2 -op.expandtab = true - -op.smartindent = true -op.wrap = false - -op.swapfile = false -op.backup = false -op.undodir = os.getenv("HOME") .. "/.vim/undodir" -op.undofile = true - -op.hlsearch = false -op.incsearch = true - -op.termguicolors = true -op.cursorline = true - -op.scrolloff = 8 - --- autoreload a file after inactivity -op.autoread = true -vim.api.nvim_command([[au CursorHold * checktime]]) - -op.updatetime = 50 - -op.colorcolumn = '120' - --- required to allow mm (mark-move) command to move file -vim.g.netrw_keepdir = 0 diff --git a/lua/talha/functions.lua b/lua/talha/functions.lua new file mode 100644 index 0000000..946bfd8 --- /dev/null +++ b/lua/talha/functions.lua @@ -0,0 +1,62 @@ +local Path = require"plenary.path" + +function CreateDailyNote() + local file_path = vim.api.nvim_buf_get_name(0) + local dir_path = file_path + local path_obj = Path:new(file_path) + + if path_obj:is_file() == true then + path_obj = path_obj:parent() -- get the parent directory + dir_path = path_obj:_fs_filename() + end + + local today_date_fmt = os.date('%Y-%m-%d') + local daily_note_file_name = today_date_fmt .. '.md' + local daily_note_file_obj = path_obj:joinpath(daily_note_file_name) + + local template_file_name = '.daily-notes-template.md' + local template_file_obj = path_obj:joinpath(template_file_name) + + local status = template_file_obj:copy({destination=daily_note_file_obj}) + + -- check if operation was a success + if status[daily_note_file_obj] == false then + print('Error! failed to create daily note') + print([[Possible Causes: + 1. No `.daily-notes-template.md` found + 2. Something went wrong with copy, in which case check nvim config]]) + return + end + + vim.cmd('e ' .. daily_note_file_obj:_fs_filename()) +end + +local function _ReloadConfigsInPath(path_selector) + local config_paths = vim.fn.glob(path_selector, true, true) + + for _, filepath in ipairs(config_paths) do + dofile(filepath) + end +end + +function ReloadLuaConfig() + for name,_ in pairs(package.loaded) do + if name:match('^linux') then + package.loaded[name] = nil + end + end + + -- Reload init/ directory + local lua_path_selector = vim.fn.stdpath('config') .. '/lua/**/*.lua' + _ReloadConfigsInPath(lua_path_selector) + + -- local after_path_selector = vim.fn.stdpath('config') .. '/after/**/*.lua' + _ReloadConfigsInPath(after_path_selector) + + print('Nvim configurations reloaded') +end + +function ToggleSpellCheck() + vim.opt.spell = not(vim.opt.spell:get()) + vim.opt.spelllang = 'en_us' +end diff --git a/lua/talha/init.lua b/lua/talha/init.lua new file mode 100644 index 0000000..2babaca --- /dev/null +++ b/lua/talha/init.lua @@ -0,0 +1,4 @@ +require("talha.remap") +require("talha.set") +require("talha.functions") + diff --git a/lua/talha/packer.lua b/lua/talha/packer.lua new file mode 100644 index 0000000..eea7520 --- /dev/null +++ b/lua/talha/packer.lua @@ -0,0 +1,40 @@ +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.2', + -- or , branch = '0.1.x', + requires = { {'nvim-lua/plenary.nvim'} } + } + + + use({ 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }) + + -- colorschemes + use { "ellisonleao/gruvbox.nvim" } + + use { "theprimeagen/harpoon" } + + use('mbbill/undotree') + + use('tpope/vim-fugitive') + + use { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v2.x', + requires = { + -- LSP Support + {'neovim/nvim-lspconfig'}, -- Required + {'williamboman/mason.nvim'}, -- Optional + {'williamboman/mason-lspconfig.nvim'}, -- Optional + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, -- Required + {'hrsh7th/cmp-nvim-lsp'}, -- Required + {'L3MON4D3/LuaSnip'}, -- Required + } + } +end) diff --git a/lua/talha/remap.lua b/lua/talha/remap.lua new file mode 100644 index 0000000..442ec9d --- /dev/null +++ b/lua/talha/remap.lua @@ -0,0 +1,37 @@ +vim.g.mapleader = " " + +-- open project view with netrw +vim.keymap.set("n", "pv", vim.cmd.Ex) + +-- file splitting +vim.keymap.set("n", "vs", vim.cmd.vsplit) +vim.keymap.set("n", "hs", vim.cmd.split) + +-- moving selected lines across lines +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +-- not moving cursor when bringing files up +vim.keymap.set("n", "J", "mzJ`z") + +-- keep cursor in screen center when moving up and down +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") + +-- keep cursor in screen center when traversing in find +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +vim.keymap.set("x", "p", "\"_dP") + +-- copying to system clipboard +vim.keymap.set("n", "y", [["+y]]) +vim.keymap.set("v", "y", [["+y]]) +vim.keymap.set("n", "Y", [["+Y]]) + +-- deleting without polluting vim clipboard +vim.keymap.set({"n", "x"}, "x", [["_x]]) +vim.keymap.set({"n", "x"}, "X", [["_d]]) + +-- global substitute the word cursor is on in current file +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) diff --git a/lua/talha/set.lua b/lua/talha/set.lua new file mode 100644 index 0000000..0366b03 --- /dev/null +++ b/lua/talha/set.lua @@ -0,0 +1,36 @@ +local op = vim.opt + +op.nu = true +op.relativenumber = true + +op.tabstop = 2 +op.softtabstop = 2 +op.shiftwidth = 2 +op.expandtab = true + +op.smartindent = true +op.wrap = false + +op.swapfile = false +op.backup = false +op.undodir = os.getenv("HOME") .. "/.vim/undodir" +op.undofile = true + +op.hlsearch = false +op.incsearch = true + +op.termguicolors = true +op.cursorline = true + +op.scrolloff = 8 + +-- autoreload a file after inactivity +op.autoread = true +vim.api.nvim_command([[au CursorHold * checktime]]) + +op.updatetime = 50 + +op.colorcolumn = '120' + +-- required to allow mm (mark-move) command to move file +vim.g.netrw_keepdir = 0 diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua index 08593d0..1663afb 100644 --- a/plugin/packer_compiled.lua +++ b/plugin/packer_compiled.lua @@ -49,8 +49,8 @@ local function save_profiles(threshold) end time([[Luarocks path setup]], true) -local package_path_str = "/home/talha/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/home/talha/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +local package_path_str = "/home/talha/.cache/nvim/packer_hererocks/2.1.1692716794/share/lua/5.1/?.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.1692716794/share/lua/5.1/?/init.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.1692716794/lib/luarocks/rocks-5.1/?.lua;/home/talha/.cache/nvim/packer_hererocks/2.1.1692716794/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/talha/.cache/nvim/packer_hererocks/2.1.1692716794/lib/lua/5.1/?.so" if not string.find(package.path, package_path_str, 1, true) then package.path = package.path .. ';' .. package_path_str end @@ -84,6 +84,16 @@ _G.packer_plugins = { path = "/home/talha/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", url = "https://github.com/hrsh7th/cmp-nvim-lsp" }, + ["gruvbox.nvim"] = { + loaded = true, + path = "/home/talha/.local/share/nvim/site/pack/packer/start/gruvbox.nvim", + url = "https://github.com/ellisonleao/gruvbox.nvim" + }, + harpoon = { + loaded = true, + path = "/home/talha/.local/share/nvim/site/pack/packer/start/harpoon", + url = "https://github.com/theprimeagen/harpoon" + }, ["lsp-zero.nvim"] = { loaded = true, path = "/home/talha/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", @@ -124,11 +134,6 @@ _G.packer_plugins = { path = "/home/talha/.local/share/nvim/site/pack/packer/start/plenary.nvim", url = "https://github.com/nvim-lua/plenary.nvim" }, - ["rose-pine"] = { - loaded = true, - path = "/home/talha/.local/share/nvim/site/pack/packer/start/rose-pine", - url = "https://github.com/rose-pine/neovim" - }, ["telescope.nvim"] = { loaded = true, path = "/home/talha/.local/share/nvim/site/pack/packer/start/telescope.nvim", -- cgit v1.2.3