-------------------------------------------------------------------------------- -- Toggles -------------------------------------------------------------------------------- -- Clear highlighted searched on pressing in normal mode vim.keymap.set('n', '', 'nohlsearch', { desc = 'Hide search results' }) 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' }) -------------------------------------------------------------------------------- -- Movements -------------------------------------------------------------------------------- -- 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' }) -- make j and k move by visual lines, not actual lines vim.keymap.set({ 'v', 'n' }, 'j', 'gj', { desc = 'move up' }) vim.keymap.set({ 'v', 'n' }, 'k', 'gk', { desc = 'move down' }) -- 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', '', 'lwi', { desc = 'Go a word further' }) vim.keymap.set('i', '', 'lbi', { desc = 'Go a word backward' }) vim.keymap.set('i', '', 'lea', { desc = 'Go a to next word end' }) -- navigate hjkl in insert mode vim.keymap.set('i', '', '', { desc = 'Move left' }) vim.keymap.set('i', '', '', { desc = 'Move down' }) vim.keymap.set('i', '', '', { desc = 'Move up' }) vim.keymap.set('i', '', '', { desc = 'Move right' }) -- move to window -- See `:help wincmd` for a list of all window commands vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) -- 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' }) -- let me out!!! vim.keymap.set({ 'n', 'v' }, 'qqq', 'bnextbd #', { desc = '[Q]uit the current window' }) vim.keymap.set({ 'n', 'v' }, '', 'bnextbc #', { desc = '[C]lose the current buffer' }) vim.keymap.set({ 'n' }, '#', "'", { desc = '[Q]uit the current window' }) -------------------------------------------------------------------------------- -- Workspace, buffer and window manipulation -------------------------------------------------------------------------------- -- split windows vim.keymap.set('n', '"', 'vsplit', { desc = 'Split the window vertically' }) vim.keymap.set('n', '%', 'split', { desc = 'Split the window horizontally' }) vim.keymap.set('n', 'w"', 'vnew', { desc = 'Split the window vertically (new buffer)' }) vim.keymap.set('n', 'w%', 'new', { desc = 'Split the window horizontally (new buffer)' }) -- window actions vim.keymap.set('n', 'wbn', 'enew', { desc = 'Open a [N]ew buffer' }) vim.keymap.set('n', 'wbc', 'bw', { desc = '[C]lose current buffer' }) -- :bd would keep in background vim.keymap.set('n', '', 'resize +1', { desc = 'Resize window' }) 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', '', 'bnext', { desc = 'Next Buffer' }) vim.keymap.set('n', '', 'bprev', { desc = 'Last Buffer' }) 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('n', 'n', 'enew', { desc = '[N]ew Buffer' }) vim.keymap.set('t', '', vim.api.nvim_replace_termcodes('', true, true, true), { desc = 'Leave terminal mode' }) -------------------------------------------------------------------------------- -- 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' }) -- paste from system clipboard vim.keymap.set({ 'n', 'v' }, 'p', '"+p', { desc = '[P]aste from system' }) vim.keymap.set({ 't', 'n', 'v' }, '', '"+pi', { desc = 'Paste the system clipboard' }) -- do not overwrite the register when pasting (kept defaults) vim.keymap.set({ 'v' }, 'P', 'P', { desc = '[P]aste to selected' }) vim.keymap.set({ 'v' }, 'p', 'p', { desc = '[p]aste to selected and copy to register' }) -- 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' }) -- add lines from normal and visual, with insert mode vim.keymap.set({ 'n', 'v' }, 'O', 'O', { desc = 'Insert a line above and insert' }) vim.keymap.set({ 'n', 'v' }, 'o', 'o', { desc = 'Insert a line below and insert' }) vim.keymap.set({ 'n', 'v' }, 'Oi', 'O', { desc = 'Insert a line above and insert' }) vim.keymap.set({ 'n', 'v' }, 'oi', 'o', { desc = 'Insert a line below and insert' }) -- make current line a blank line vim.keymap.set({ 'n', 'v' }, 'do', 'Vc', { desc = '[D]o [O]ver / Rewrite line' }) -- 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+1', { desc = 'Move line down' }) vim.keymap.set({ 'n', 'v' }, '', '<<', { desc = 'Less indentation' }) vim.keymap.set({ 'n', 'v' }, '', '>>', { desc = 'More indentation' }) -- format a long line into multiple with length 80 vim.keymap.set({ 'v' }, 'fl', ':!fmt -w80', { desc = '[F]ormat long [L]ines into smaller ones' }) -------------------------------------------------------------------------------- -- 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' }) -------------------------------------------------------------------------------- -- Formating -------------------------------------------------------------------------------- -- discard F15 vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '') vim.keymap.set({ 'i', 't', 'x', 'n', 'v' }, '', '')