From 9c6e3a5d1879c4f3ac45310649aee914413c9f92 Mon Sep 17 00:00:00 2001 From: afranco Date: Sat, 27 Apr 2024 16:02:41 +0100 Subject: [PATCH] chore(nvim): harpoon and other efficiency stuff --- .config/nvim/lua/core/variables.lua | 6 +- .config/nvim/lua/plugins/cmp.lua | 68 ++++-------------- .config/nvim/lua/plugins/lazy.lua | 91 ++++++++++--------------- .config/nvim/lua/plugins/lspconfig.lua | 20 ++++-- .config/nvim/lua/plugins/telescope.lua | 36 ++++++++++ .config/nvim/lua/plugins/treesitter.lua | 25 +++++-- 6 files changed, 122 insertions(+), 124 deletions(-) diff --git a/.config/nvim/lua/core/variables.lua b/.config/nvim/lua/core/variables.lua index b0669b5..4ad5e79 100644 --- a/.config/nvim/lua/core/variables.lua +++ b/.config/nvim/lua/core/variables.lua @@ -25,8 +25,8 @@ vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true --quickfix keybinds -vim.keymap.set("n", "", "cnextzz") -vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "", "cnextzz") --buffer keybinds vim.keymap.set("n", "", "bp") vim.keymap.set("n", "", "bn") @@ -46,4 +46,4 @@ vim.g.jukit_pdf_viewer = 'zathura' vim.g.jukit_mappings = 0 --Format Options vim.opt.formatoptions:remove("ro") - +--Sign gutter always on diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index fa390ac..80b163b 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -19,38 +19,6 @@ if not lspkind_status_ok then return end --- 󰃐 󰆩 󰙅 󰛡  󰅲 some other good icons -local kind_icons = { - Text = "󰉿", - Method = "m", - Function = "󰊕", - Constructor = "", - Field = "", - Variable = "󰆧", - Class = "󰌗", - Interface = "", - Module = "", - Property = "", - Unit = "", - Value = "󰎠", - Enum = "", - Keyword = "󰌋", - Snippet = "", - Color = "󰏘", - File = "󰈙", - Reference = "", - Folder = "󰉋", - EnumMember = "", - Constant = "󰇽", - Struct = "", - Event = "", - Operator = "󰆕", - TypeParameter = "󰊄", - Copilot = "", - DB = "󰆼", -} --- find more here: https://www.nerdfonts.com/cheat-sheet - cmp.setup({ snippet = { expand = function(args) @@ -71,38 +39,25 @@ cmp.setup({ { "i", "c" } ), [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - -- Accept currently selected item. If none selected, do nothing. - [""] = cmp.mapping(function(fallback) - if luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then + [""] = cmp.mapping(function() + if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - else - fallback() end end), - [""] = cmp.mapping(function(fallback) + [""] = cmp.mapping(function() if luasnip.jumpable(-1) then luasnip.jump(-1) - else - fallback() end end), }, formatting = { fields = { "kind", "abbr", "menu" }, format = lspkind.cmp_format({ - mode = "symbol_text", -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - -- can also be a function to dynamically calculate max width such as - -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end, - ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first) - show_labelDetails = true, -- show labelDetails in menu. Disabled by default + mode = "symbol_text", + maxwidth = 50, + ellipsis_char = "...", + show_labelDetails = true, - -- The function below will be called before any actual modifications from lspkind - -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) before = function(entry, vim_item) vim_item.menu = ({ nvim_lsp = "[LSP]", @@ -113,11 +68,16 @@ cmp.setup({ end, }), }, + preselect = cmp.PreselectMode.None, sorting = { + priority_weight = 2, comparators = { - cmp.config.compare.exact, cmp.config.compare.offset, + cmp.config.compare.exact, + cmp.config.compare.score, + cmp.config.compare.kind, cmp.config.compare.recently_used, + cmp.config.compare.locality, --Make entries that start with underline appear after function(entry1, entry2) @@ -134,8 +94,8 @@ cmp.setup({ }, }, sources = cmp.config.sources({ - { name = "nvim_lsp" }, { name = "nvim_lua" }, + { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" }, }, { diff --git a/.config/nvim/lua/plugins/lazy.lua b/.config/nvim/lua/plugins/lazy.lua index 8b1079c..efd8d00 100644 --- a/.config/nvim/lua/plugins/lazy.lua +++ b/.config/nvim/lua/plugins/lazy.lua @@ -29,6 +29,15 @@ lazy.setup({ end, }, + { + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + require("plugins.harpoon") + end + }, + "vimpostor/vim-tpipeline", { @@ -61,7 +70,15 @@ lazy.setup({ "folke/todo-comments.nvim", event = "VeryLazy", dependencies = { "nvim-lua/plenary.nvim" }, - opts = {}, + opts = { + vim.keymap.set("n", "]t", function() + require("todo-comments").jump_next() + end, { desc = "Next todo comment" }), + + vim.keymap.set("n", "[t", function() + require("todo-comments").jump_prev() + end, { desc = "Previous todo comment" }) + }, }, { @@ -181,6 +198,11 @@ lazy.setup({ end, }, + { + 'leoluz/nvim-dap-go', + opts = {} + }, + { "williamboman/mason.nvim", config = function() @@ -196,61 +218,12 @@ lazy.setup({ require("plugins.lspconfig") end, }, + --Better quick fix { - "folke/trouble.nvim", - branch = "dev", - keys = { - { - "xx", - "Trouble diagnostics toggle", - desc = "Diagnostics (Trouble)", - }, - { - "xX", - "Trouble diagnostics toggle filter.buf=0", - desc = "Buffer Diagnostics (Trouble)", - }, - { - "cs", - "Trouble symbols toggle focus=false", - desc = "Symbols (Trouble)", - }, - { - "cl", - "Trouble lsp toggle focus=false win.position=right", - desc = "LSP Definitions / references / ... (Trouble)", - }, - { - "xL", - "Trouble loclist toggle", - desc = "Location List (Trouble)", - }, - { - "xQ", - "Trouble qflist toggle", - desc = "Quickfix List (Trouble)", - }, - }, - opts = { - modes = { - mydiags = { - mode = "diagnostics", -- inherit from diagnostics mode - filter = { - any = { - buf = 0, -- current buffer - { - severity = vim.diagnostic.severity.ERROR, -- errors only - -- limit to files in the current project - function(item) - return item.filename:find(vim.loop.cwd(), 1, true) - end, - }, - }, - }, - } - } - } + 'kevinhwang91/nvim-bqf', + ft = 'qf' }, + 'junegunn/fzf', { "stevearc/conform.nvim", @@ -293,12 +266,14 @@ lazy.setup({ -- Syntax Highlighting { "nvim-treesitter/nvim-treesitter", + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects' + }, config = function() require("plugins.treesitter") end, }, - "kaarmu/typst.vim", --Sticky headers { @@ -315,7 +290,11 @@ lazy.setup({ "nvim-telescope/telescope.nvim", tag = "0.1.4", -- or , branch = '0.1.x', - dependencies = { "nvim-lua/plenary.nvim" }, + dependencies = { + "nvim-lua/plenary.nvim", + 'nvim-telescope/telescope-ui-select.nvim', + { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' } + }, config = function() require("plugins.telescope") end, diff --git a/.config/nvim/lua/plugins/lspconfig.lua b/.config/nvim/lua/plugins/lspconfig.lua index 615ab54..bde13ae 100644 --- a/.config/nvim/lua/plugins/lspconfig.lua +++ b/.config/nvim/lua/plugins/lspconfig.lua @@ -12,6 +12,8 @@ vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) -- Enable completion triggered by vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + vim.opt_local.signcolumn=numbers + local telescope = require("telescope.builtin") local conform = require("conform") @@ -28,13 +30,13 @@ vim.api.nvim_create_autocmd("LspAttach", { vim.keymap.set("n", "q", vim.diagnostic.setloclist, bufopts) vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts) vim.keymap.set("n", "gd", telescope.lsp_definitions, bufopts) + vim.keymap.set("n", "gr", telescope.lsp_references, bufopts) vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) vim.keymap.set("n", "gi", telescope.lsp_implementations, bufopts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, bufopts) + vim.keymap.set("n", "k", vim.lsp.buf.signature_help, bufopts) vim.keymap.set("n", "D", vim.lsp.buf.type_definition, bufopts) vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) vim.keymap.set("n", "ca", vim.lsp.buf.code_action, bufopts) - vim.keymap.set("n", "gr", telescope.lsp_references, bufopts) vim.keymap.set("n", "ge", function() vim.diagnostic.goto_next() end, bufopts) vim.keymap.set("n", "gE", function() vim.diagnostic.goto_prev() end, bufopts) vim.keymap.set("n", "fo", function() conform.format({ lsp_fallback = true }) end, bufopts) @@ -54,7 +56,7 @@ mason_lspconfig.setup_handlers({ capabilities = capabilities, }) end, - ["gopls"] = function () + ["gopls"] = function() lspconfig["gopls"].setup({ capabilities = capabilities, settings = { @@ -79,11 +81,17 @@ mason_lspconfig.setup_handlers({ capabilities = capabilities, settings = { Lua = { - library = { - unpack(vim.api.nvim_get_runtime_file('', true)) + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", }, diagnostics = { - globals = { 'vim' }, + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), }, hint = { enable = true } }, diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index c55f118..49aaf80 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -1,5 +1,41 @@ +local telescope = require('telescope') +local actions = require("telescope.actions") + +telescope.setup { + defaults = { + layout_strategy = "horizontal", + mappings = { + i = { + [""] = actions.close, + }, + }, + }, + pickers = { + find_files = { + previewer = false, + layout_strategy = "vertical", + layout_config = { + height = 0.7, + width = 0.5 + }, + }, + live_grep = { + only_sort_text = true, + previewer = true, + } + }, + extensions = { + ["ui-select"] = { + require("telescope.themes").get_cursor {} + } + } +} +telescope.load_extension('fzf') +telescope.load_extension("ui-select") + local builtin = require('telescope.builtin') vim.keymap.set('n', 'ff', builtin.find_files, {}) vim.keymap.set('n', 'fg', builtin.live_grep, {}) vim.keymap.set('n', 'fb', builtin.buffers, {}) +vim.keymap.set('n', 'fs', builtin.treesitter, {}) vim.keymap.set('n', 'fh', builtin.help_tags, {}) diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua index d4a6fec..995a448 100644 --- a/.config/nvim/lua/plugins/treesitter.lua +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -4,11 +4,6 @@ if not present then end require('nvim-treesitter.install').update({ with_sync = true }) -local present, orgmode = pcall(require, "orgmode") -if present then - require('orgmode').setup_ts_grammar() -end - local options = { @@ -22,6 +17,26 @@ local options = { indent = { enable = true, }, + textobjects = { + select = { + enable = true, + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ab"] = "@block.outer", + ["ib"] = "@block.inner", + }, + selection_modes = { + ['@block.outer'] = 'v', -- charwise + ['@block.inner'] = 'v', -- charwise + ['@function.outer'] = 'V', -- linewise + }, + include_surrounding_whitespace = true, + }, + }, } treesitter.setup(options)