From 84c3b5ac7d47a1a365f38d197be7accd51bb7e46 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 4 Jul 2024 14:43:32 +0200 Subject: [PATCH] moar keymaps and plugins --- lua/custom/plugins/configs/lsp.lua | 5 +- lua/custom/plugins/editing.lua | 26 +++++++ lua/custom/plugins/init.lua | 106 ++++++++--------------------- lua/custom/plugins/lsp.lua | 15 +++- lua/custom/plugins/telescope.lua | 1 + lua/custom/plugins/ui.lua | 86 ++++++++++++++++++++++- 6 files changed, 156 insertions(+), 83 deletions(-) create mode 100644 lua/custom/plugins/editing.lua create mode 100644 lua/custom/plugins/telescope.lua diff --git a/lua/custom/plugins/configs/lsp.lua b/lua/custom/plugins/configs/lsp.lua index b0301e8..58b39fa 100644 --- a/lua/custom/plugins/configs/lsp.lua +++ b/lua/custom/plugins/configs/lsp.lua @@ -1,5 +1,6 @@ local lspconfig = require 'lspconfig' local lspsettings = require 'custom.plugins.configs.lspsettings' +local capabilities = vim.lsp.protocol.make_client_capabilities() -- these are using the defaults local servers = { @@ -16,7 +17,9 @@ local servers = { } for _, lsp in ipairs(servers) do - lspconfig[lsp].setup {} + lspconfig[lsp].setup { + capabilities = capabilities, + } end local server_with_settings = { diff --git a/lua/custom/plugins/editing.lua b/lua/custom/plugins/editing.lua new file mode 100644 index 0000000..dbca3bb --- /dev/null +++ b/lua/custom/plugins/editing.lua @@ -0,0 +1,26 @@ +return { + { + 'numToStr/Comment.nvim', + keys = { + { 'gcc', mode = 'n', desc = 'Comment toggle current line' }, + { 'gc', mode = { 'n', 'o' }, desc = 'Comment toggle linewise' }, + { 'gc', mode = 'x', desc = 'Comment toggle linewise (visual)' }, + { 'gbc', mode = 'n', desc = 'Comment toggle current block' }, + { 'gb', mode = { 'n', 'o' }, desc = 'Comment toggle blockwise' }, + { 'gb', mode = 'x', desc = 'Comment toggle blockwise (visual)' }, + }, + init = function() + require('core.utils').load_mappings 'comment' + end, + config = function(_, opts) + vim.keymap.set('n', 'c', function() + require('Comment.api').toggle.linewise.current() + end, { desc = '[T]oggle [C]omment' }) + vim.keymap.set('v', 'c', function() + require('Comment.api').toggle.linewise.current() + end, { desc = '[T]oggle [C]omment' }) + + require('Comment').setup(opts) + end, + }, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 6953407..cf3b196 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,75 +1,6 @@ return { - -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically - -- NOTE: Plugins can also be added by using a table, - -- with the first argument being the link and the following - -- keys can be used to configure plugin behavior/loading/etc. - -- - -- Use `opts = {}` to force a plugin to be loaded. - -- - -- This is equivalent to: - -- require('Comment').setup({}) - - -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, - - -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. This is equivalent to the following Lua: - -- require('gitsigns').setup({ ... }) - -- - -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. - -- - -- This is often very useful to both group configuration, as well as handle - -- lazy loading plugins that don't need to be loaded immediately at startup. - -- - -- For example, in the following configuration, we use: - -- event = 'VimEnter' - -- - -- which loads which-key before all the UI elements are loaded. Events can be - -- normal autocommands events (`:help autocmd-events`). - -- - -- Then, because we use the `config` key, the configuration only runs - -- after the plugin has been loaded: - -- config = function() ... end - - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VimEnter', -- Sets the loading event to 'VimEnter' - config = function() -- This is the function that runs, AFTER loading - require('which-key').setup() - - -- Document existing key chains - require('which-key').register { - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['f'] = { name = '[F]ind', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - } - -- visual mode - require('which-key').register({ - ['h'] = { 'Git [H]unk' }, - }, { mode = 'v' }) - end, - }, - -- NOTE: Plugins can specify dependencies. -- -- The dependencies are proper plugin specifications as well - anything @@ -79,10 +10,10 @@ return { { -- Fuzzy Finder (files, lsp, etc) 'nvim-telescope/telescope.nvim', - event = 'VimEnter', - branch = '0.1.x', + cmd = 'Telescope', dependencies = { 'nvim-lua/plenary.nvim', + 'nvim-treesitter/nvim-treesitter', { -- If encountering errors, see telescope-fzf-native README for installation instructions 'nvim-telescope/telescope-fzf-native.nvim', @@ -138,6 +69,19 @@ return { require('telescope.themes').get_dropdown(), }, }, + defaults = { + vimgrep_arguments = { + 'rg', + '-L', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case', + }, + prompt_prefix = '  ', + }, } -- Enable Telescope extensions if they are installed @@ -149,16 +93,20 @@ return { vim.keymap.set('n', 'fh', builtin.help_tags, { desc = '[F]ind [H]elp' }) vim.keymap.set('n', 'fk', builtin.keymaps, { desc = '[F]ind [K]eymaps' }) vim.keymap.set('n', 'ff', builtin.find_files, { desc = '[F]ind [F]iles' }) - vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[F]ind [S]elect Telescope' }) - vim.keymap.set('n', 'fw', builtin.grep_string, { desc = '[F]ind current [W]ord' }) - vim.keymap.set('n', 'fg', builtin.live_grep, { desc = '[F]ind by [G]rep' }) + vim.keymap.set('n', 'ft', builtin.builtin, { desc = '[F]ind [T]elescope' }) + vim.keymap.set('n', 'fw', builtin.live_grep, { desc = '[F]ind a [W]ord interactively' }) + vim.keymap.set('n', 'fcw', builtin.grep_string, { desc = '[F]ind [C]urrent [W]ord' }) vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[F]ind [D]iagnostics' }) vim.keymap.set('n', 'fr', builtin.resume, { desc = '[F]ind [R]esume' }) - vim.keymap.set('n', 'f.', builtin.oldfiles, { desc = '[F]ind Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'fof.', builtin.oldfiles, { desc = '[F]ind [O]ld Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = '[F]ind existing [B]uffers' }) + vim.keymap.set('n', 'fm', builtin.marks, { desc = '[F]ind book[M]arks' }) + vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[F]ind LSP [D]iagnostigs' }) + vim.keymap.set('n', 'fs', builtin.lsp_dynamic_workspace_symbols, { desc = '[F]ind LSP [S]ymbols' }) -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() + vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, @@ -168,7 +116,7 @@ return { -- It's also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() + vim.keymap.set('n', 'f/', function() builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files', @@ -176,9 +124,9 @@ return { end, { desc = '[F]ind [/] in Open Files' }) -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() + vim.keymap.set('n', 'fnf', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[F]ind [N]eovim files' }) + end, { desc = '[F]ind [N]eovim [F]iles' }) end, }, diff --git a/lua/custom/plugins/lsp.lua b/lua/custom/plugins/lsp.lua index 8583502..56c7785 100644 --- a/lua/custom/plugins/lsp.lua +++ b/lua/custom/plugins/lsp.lua @@ -2,7 +2,20 @@ return { { 'neovim/nvim-lspconfig', config = function() - require "custom.plugins.configs.lsp" + require 'custom.plugins.configs.lsp' end, }, + -- See `:help gitsigns` to understand what the configuration keys do + { -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + }, + }, } diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/lua/custom/plugins/telescope.lua @@ -0,0 +1 @@ +return {} diff --git a/lua/custom/plugins/ui.lua b/lua/custom/plugins/ui.lua index 08003bf..d37e90c 100644 --- a/lua/custom/plugins/ui.lua +++ b/lua/custom/plugins/ui.lua @@ -1,5 +1,4 @@ return { - { 'nvim-tree/nvim-tree.lua', cmd = { 'NvimTreeToggle', 'NvimTreeFocus' }, @@ -32,7 +31,7 @@ return { }, { 'kdheepak/lazygit.nvim', - keys = { 'gg' }, + keys = { 'gg', ' LazyGit ', 'Open LazyGit' }, cmd = 'LazyGit', -- optional for floating window border decoration dependencies = { @@ -130,7 +129,28 @@ return { }) end, }, + { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + config = function() -- This is the function that runs, AFTER loading + require('which-key').setup() + -- Document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['f'] = { name = '[F]ind', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + } + -- visual mode + require('which-key').register({ + ['h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) + end, + }, { 'RRethy/vim-illuminate', lazy = false, @@ -220,4 +240,66 @@ return { }, }, }, + { + 'folke/trouble.nvim', + cmd = 'Trouble', + opts = { use_diagnostic_signs = true }, + -- stylua: ignore + keys = { + { 'rb', "Trouble diagnostics toggle filter.buf=0", desc = 'Document Diagnostics (Trouble)' }, + { 'rr', 'Trouble diagnostics toggle', desc = 'Workspace Diagnostics (Trouble)' }, + { 'rq', "Trouble qflist toggle", desc = 'Quickfix List (Trouble)' }, + { 'rl', "Trouble loclist toggle", desc = 'Location List (Trouble)' }, + { 'rd', "Trouble symbols", desc = 'LSP symbols (Trouble)' }, + { 'rt', "Trouble todo", desc = 'Todos (Trouble)' }, + { + '[q', + function() + if require('trouble').is_open() then + require('trouble').previous({ skip_groups = true, jump = true }) + else + vim.cmd.cprev() + end + end, + desc = 'Previous trouble/quickfix item', + }, + { + ']q', + function() + if require('trouble').is_open() then + require('trouble').next({ skip_groups = true, jump = true }) + else + vim.cmd.cnext() + end + end, + desc = 'Next trouble/quickfix item', + }, + }, + }, + { + 'akinsho/toggleterm.nvim', + keys = { + { '', 'exe v:count1 "ToggleTerm direction=float"', desc = 'Toggle a big floating terminal' }, + { '', 'exe v:count1 "ToggleTerm direction=float"', desc = 'Toggle a big floating terminal' }, + { '', 'exe v:count1 "ToggleTerm direction=tab"', desc = 'Toggle a terminal in a new tab' }, + { '', 'exe v:count1 "ToggleTerm direction=horizontal"', desc = 'Toggle a horizontal terminal' }, + { '', 'exe v:count1 "ToggleTerm direction=vertical"', desc = 'Toggle a vertical terminal' }, + }, + cmd = 'ToggleTerm', + opts = { + size = function(term) + if term.direction == 'horizontal' then + return vim.o.lines * 0.35 + elseif term.direction == 'vertical' then + return vim.o.columns * 0.35 + else + return 20 + end + end, + open_mapping = false, + float_opts = { + border = 'curved', + }, + }, + }, }