diff --git a/lua/custom/maps/init.lua b/lua/custom/maps/init.lua index e8cd816..5b0cae6 100644 --- a/lua/custom/maps/init.lua +++ b/lua/custom/maps/init.lua @@ -4,20 +4,33 @@ -- Clear highlighted searched on pressing in normal mode vim.keymap.set('n', '', 'nohlsearch', { desc = 'Hide search results' }) --- line numbers vim.keymap.set('n', 'tn', ' set nu! ', { desc = '[T]oggle line [N]umbers' }) vim.keymap.set('n', 'trn', ' set rnu! ', { desc = '[T]oggle [R]elative line [N]umbers' }) +vim.keymap.set('n', 'tw', ' set wrap! ', { desc = '[T]oggle [W]rap' }) +vim.keymap.set('n', 'ts', ' set spell! ', { desc = '[T]oggle [S]pellcheck' }) -------------------------------------------------------------------------------- --- Insert movements +-- Movements -------------------------------------------------------------------------------- --- go to beginning and end +-- make big movements up and down +vim.keymap.set({ 't', 'i', 'v', 'n' }, '', '', { desc = 'move a many lines up' }) +vim.keymap.set({ 't', 'i', 'v', 'n' }, '', '', { desc = 'move a many lines down' }) + +-- move to end and start of lines with H and L +vim.keymap.set({ 'v', 'n' }, 'H', '', { desc = 'move to start of line' }) +vim.keymap.set({ 'v', 'n' }, 'L', '', { desc = 'move to end of line' }) + +-- move+scroll +vim.keymap.set({ 'v', 'n' }, 'zk', '', { desc = 'move and scroll up' }) +vim.keymap.set({ 'v', 'n' }, 'zj', '', { desc = 'move and scroll down' }) + +-- go to beginning and end in insert mode vim.keymap.set('i', '', '^i', { desc = 'Go to the start of the line' }) vim.keymap.set('i', '', '', { desc = 'Go to the end of the line' }) vim.keymap.set('i', '', 'wa', { desc = 'Go a word further' }) vim.keymap.set('i', '', 'ba', { desc = 'Go a word backward' }) --- navigate within insert mode +-- navigate hjkl in insert mode vim.keymap.set('i', '', '', { desc = 'Move left' }) vim.keymap.set('i', '', '', { desc = 'Move right' }) vim.keymap.set('i', '', '', { desc = 'Move down' }) @@ -38,13 +51,14 @@ vim.keymap.set('n', '', 'resize -1', { desc = 'Resize window' } vim.keymap.set('n', '', 'vertical resize +1', { desc = 'Resize window vertically' }) vim.keymap.set('n', '', 'vertical resize -1', { desc = 'Resize window vertically' }) - -- tabs/workspaces vim.keymap.set('n', 'wn', 'tabnew', { desc = 'Open a [N]ew [W]orkspace/Tab' }) vim.keymap.set('n', 'wc', 'tabclose', { desc = '[C]lose a [W]orkspace/Tab' }) vim.keymap.set('n', 'wk', 'tabnext', { desc = 'Next [W]orkspace/Tab' }) vim.keymap.set('n', 'wj', 'tabprevious', { desc = 'Last [W]orkspace/Tab' }) +vim.keymap.set('t', '', vim.api.nvim_replace_termcodes('', true, true, true), { desc = 'Leave terminal mode' }) + -------------------------------------------------------------------------------- -- Move to things -------------------------------------------------------------------------------- @@ -58,3 +72,40 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the upper win -- diagnostics vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) + +-------------------------------------------------------------------------------- +-- Editing +-------------------------------------------------------------------------------- +-- copy to system clipboard +vim.keymap.set({ 'n', 'v' }, 'y', '"+y', { desc = '[Y]ank to system' }) +vim.keymap.set({ 'n', 'v' }, 'Y', '"+Y', { desc = '[Y]ank to system' }) +vim.keymap.set({ 'n', 'v' }, 'yy', '"+yy', { desc = '[Y]ank to system' }) +vim.keymap.set({ 't', 'n', 'v' }, '', '"+pi', { desc = 'Paste the system clipboard' }) + +-- add lines from normal and visual, without insert mode +vim.keymap.set({ 'n', 'v' }, 'OO', 'O', { desc = 'Insert a line above' }) +vim.keymap.set({ 'n', 'v' }, 'oo', 'o', { desc = 'Insert a line below' }) + +-- substitute, normally on 's', but the leap plugin is more useful on 's' +vim.keymap.set({ 'n' }, 's', 's', { desc = '[S]ubstitute hovered text' }) + +-- do something useful with the arrow keys: +-- move lines up/down and change indentation +vim.keymap.set({ 'n', 'v' }, '', ' move-2', { desc = 'Move line up' }) +vim.keymap.set({ 'n', 'v' }, '', ' move+2', { desc = 'Move line down' }) +vim.keymap.set({ 'n', 'v' }, '', '<<', { desc = 'Less indentation' }) +vim.keymap.set({ 'n', 'v' }, '', '>>', { desc = 'More indentation' }) + +-------------------------------------------------------------------------------- +-- Formating +-------------------------------------------------------------------------------- +-- format the current buffer +vim.keymap.set('n', 'ff', function() + require('conform').format() +end, { desc = '[F]ormat buffer' }) +vim.keymap.set('n', 'fF', function() + vim.lsp.buf.format() +end, { desc = '[F]ormat buffer (no plugin)' }) +vim.keymap.set('n', 'fw', function() + require('mini.trailspace').trim() +end, { desc = '[F]ormat remove [W]hitespace' }) diff --git a/lua/custom/plugins/lsp.lua b/lua/custom/plugins/lsp.lua index 9fce50c..435f7ce 100644 --- a/lua/custom/plugins/lsp.lua +++ b/lua/custom/plugins/lsp.lua @@ -17,49 +17,6 @@ return { }, config = function() require 'custom.plugins.configs.lsp' - local cmp = require 'cmp' -- this is nvim-cmp - keys = { - { '', cmp.mapping.select_prev_item(), desc = 'Next completion' }, - { '', cmp.mapping.select_next_item(), desc = 'Last completion' }, - { '', cmp.mapping.complete(), desc = 'Accept completion' }, - { '', cmp.mapping.close(), desc = 'Hide completions' }, - { '', cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Insert, - select = true, - }, desc = 'Accept completion' }, - { - '', - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif require('luasnip').expand_or_jumpable() then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') - else - fallback() - end - end, { - 'i', - 's', - }), - desc = 'Next completion', - }, - { - '', - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif require('luasnip').expand_or_jumpable() then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') - else - fallback() - end - end, { - 'i', - 's', - }), - desc = 'Last completion', - }, - }, end, }, -- See `:help gitsigns` to understand what the configuration keys do @@ -179,13 +136,13 @@ return { -- Accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, + -- [''] = cmp.mapping.confirm { select = true }, -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines - --[''] = cmp.mapping.confirm { select = true }, - --[''] = cmp.mapping.select_next_item(), - --[''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua index 86b46c5..b69cc98 100644 --- a/lua/custom/plugins/telescope.lua +++ b/lua/custom/plugins/telescope.lua @@ -96,6 +96,10 @@ return { 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' }) + -- spelling + vim.keymap.set('n', 'z', builtin.spell_suggest, { desc = '[F]ind spelling' }) + vim.keymap.set('n', 'z=', builtin.spell_suggest, { desc = '[F]ind spelling' }) + -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. diff --git a/lua/custom/plugins/ui.lua b/lua/custom/plugins/ui.lua index 1b832fb..a24ef5b 100644 --- a/lua/custom/plugins/ui.lua +++ b/lua/custom/plugins/ui.lua @@ -13,6 +13,11 @@ return { { 'ggandor/leap.nvim', lazy = false, + keys = { + { 's', '(leap-forward)', desc = 'leap forward' }, + { 'S', '(leap-backward)', desc = 'leap backward' }, + { 'gs', '(leap-from-window)', desc = 'leap from window' }, + }, }, { 'ggandor/flit.nvim', @@ -31,7 +36,9 @@ return { }, { 'kdheepak/lazygit.nvim', - keys = { 'gg', ' LazyGit ', 'Open LazyGit' }, + keys = { + { 'gg', 'LazyGit', desc = 'Open LazyGit' }, + }, cmd = 'LazyGit', -- optional for floating window border decoration dependencies = { @@ -243,11 +250,11 @@ return { { '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' }, + { '', mode = { 't', 'n', 'v' }, 'exe v:count1 "ToggleTerm direction=float"', desc = 'Toggle a big floating terminal' }, + { '', mode = { 't', 'n', 'v' }, 'exe v:count1 "ToggleTerm direction=float"', desc = 'Toggle a big floating terminal' }, + { '', mode = { 't', 'n', 'v' }, 'exe v:count1 "ToggleTerm direction=tab"', desc = 'Toggle a terminal in a new tab' }, + { '', mode = { 't', 'n', 'v' }, 'exe v:count1 "ToggleTerm direction=horizontal"', desc = 'Toggle a horizontal terminal' }, + { '', mode = { 't', 'n', 'v' }, 'exe v:count1 "ToggleTerm direction=vertical"', desc = 'Toggle a vertical terminal' }, }, cmd = 'ToggleTerm', opts = {