-------------------------------------------------------------------------------- -- 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' }) -- 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' }) -- 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', 'bd!', { desc = '[Q]uit the current window' }) vim.keymap.set({ 'n', 'v' }, '', 'bw!', { desc = '[Q]uit the current window' }) 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' }) -- window actions vim.keymap.set('n', 'wbn', 'enew', { desc = 'Open a [N]ew [B]uffer' }) vim.keymap.set('n', 'wbc', 'bw', { desc = '[C]lose current [B]uffer' }) -- :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('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' }) 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' }) -- 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' })