local api = vim.api local wk = require('which-key') -- No one likes Esc api.nvim_set_keymap('i', 'jk', [[]], {noremap = true, silent = true}) -- Escape to normal mode in terminal buffer api.nvim_set_keymap('t', '', '', {noremap = true, silent = true}) -- Continuous indent api.nvim_set_keymap('v', '<', '', '>gv', {noremap = true, silent = true}) -- Clear search results -- api.nvim_set_keymap('n', '', 'noh', {noremap = true, silent = true}) ----------------- -- Normal mode -- ----------------- wk.register({ -- Better Y Y = {'y$', 'Yank to eol'}, -- Easier start and end of line H = {'^', 'Start of the line'}, L = {'$', 'End of the line'}, -- Easier moving between windows [''] = {'h', 'Go to the left window'}, [''] = {'l', 'Go to the right window'}, [''] = {'j', 'Go to the down window'}, [''] = {'k', 'Go to the up window'}, -- Copy the whole buffer [''] = {'%y+', 'Copy whole buffer'}, -- 'Legacy' save buffer -- [''] = {':w', 'Write buffer'}, -- Close buffer [''] = {':bd!', 'Close buffer'}, -- Remove trailing whitespace [''] = {':%s/\\s\\+$//e', 'Remove trailing'}, -- Resize buffer [''] = {':resize -2', 'Resize vertical -2'}, [''] = {':resize +2', 'Resize vertical +2'}, [''] = {':vertical resize -2', 'Resize horizontal -2'}, [''] = {':vertical resize +2', 'Resize horizontal +2'}, -- Switch between tabs and spaces [''] = { function() if vim.o.expandtab == true then vim.cmd('set noexpandtab nosmarttab softtabstop& shiftwidth&') vim.cmd('echomsg "Switched to indent with tabs"') else vim.opt.expandtab = true vim.opt.smarttab = true vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.cmd('echomsg "Switched to indent with 4 spaces"') end end, 'Switch indent style' }, -- Naming common keys ['['] = { name = 'Block motions (previous)', d = 'Previous diagnostics', g = 'Previous git hunk' }, [']'] = { name = 'Block motions (next)', d = 'Next diagnostics', g = 'Next git hunk' }, g = { name = 'Goto motions', d = 'Go to definition', D = 'Go to declaration', i = 'Go to implementation', r = 'Go to references' }, K = {name = 'Hover'}, z = {name = 'Misc utils'}, -- Don't need to show bufferline numbers ['1'] = 'which_key_ignore', ['2'] = 'which_key_ignore', ['3'] = 'which_key_ignore', ['4'] = 'which_key_ignore', ['5'] = 'which_key_ignore', ['6'] = 'which_key_ignore', ['7'] = 'which_key_ignore', ['8'] = 'which_key_ignore', ['9'] = 'which_key_ignore', -- Move between tabs [''] = {'BufferLineCycleNext', 'Next buffer'}, [''] = {'BufferLineCyclePrev', 'Previous buffer'}, -- NvimTree [''] = {':NvimTreeToggle', 'NvimTree'}, -- ToggleTerm [''] = {':ToggleTerm', 'Toggle terminal'} }) ----------------------------------- -- Normal mode (with leader key) -- ----------------------------------- wk.register({ c = {':ColorizerToggle', 'Toggle colorizer'}, b = { name = 'Buffer', n = {':DashboardNewFile', 'New file'} }, -- Telescope f = { name = 'Telescope', a = {':Telescope autocommands', 'Autocommands'}, b = {':Telescope buffers', 'Buffers'}, c = {':Telescope commands', 'Commands'}, e = {':Telescope file_browser', 'File browser'}, f = {':Telescope find_files', 'Find files'}, g = {':Telescope live_grep', 'Live grep'}, h = {':Telescope help_tags', 'Help tags'}, i = {':Telescope highlights', 'Highlight groups'}, j = {':Telescope symbols', 'Pick emojis'}, k = {':Telescope keymaps', 'Normal keymaps'}, m = {':Telescope marks', 'Bookmarks'}, n = {':Telescope man_pages', 'Man pages'}, o = {':Telescope oldfiles', 'Recent files'}, p = {':Telescope project display_type=full', 'Projects'}, r = {':Telescope reloader', 'Reload lua modules'}, s = {':Telescope treesitter', 'Treesitter'}, t = {':Telescope', 'Telescope'}, u = {':Telescope current_buffer_fuzzy_find', 'Search current buffer'}, v = {':Telescope vim_options', 'Vim options'}, y = {':Telescope filetypes', 'Filetypes'}, z = {':Telescope registers', 'Vim registers'} }, l = { name = 'LSP', a = 'Add workspace folder', d = 'Type definition', e = 'Line diagnostics', l = 'List workspace folders', n = 'Rename in buffer', o = 'Format buffer', q = 'Set diagnostics loclist', r = 'Remove workspace folder', s = 'Signature help', f = { name = 'Telescope', a = {':Telescope lsp_code_actions', 'Code actions'}, A = {':Telescope lsp_range_code_actions', 'Range code actions'}, d = {':Telescope lsp_document_diagnostics', 'Buffer diagnostics'}, D = {':Telescope lsp_workspace_diagnostics', 'Workspace diagnostics'}, e = {':Telescope lsp_dynamic_workspace_symbols', 'Dynamic workspace symbols'}, i = {':Telescope lsp_implementations', 'Implementations'}, n = {':Telescope lsp_definitions', 'Definitions'}, r = {':Telescope lsp_references', 'References'}, s = {':Telescope lsp_document_symbols', 'Buffer symbols'}, S = {':Telescope lsp_workspace_symbols', 'Workspace symbols'} } }, -- Git g = { name = 'Git', b = 'Blame current line', p = 'Preview hunk', r = 'Reset hunk', R = 'Reset all hunks in buffer', s = 'Stage hunk', u = 'Undo hunk', n = {':Neogit', 'Neogit'}, f = { name = 'Telescope', a = {':Telescope git_stash', 'Stash'}, b = {':Telescope git_bcommits', 'Buffer commits'}, c = {':Telescope git_commits', 'Commits'}, m = {':Telescope git_branches', 'Branches'}, s = {':Telescope git_status', 'Status'} } }, -- Tab related t = { name = 'Tab', n = {'tabnext', 'Next tab'}, p = {'tabprev', 'Previous tab'}, t = {'tabnew', 'New tab'} } }, {prefix = ''}) ----------------------------------- -- Visual mode (with leader key) -- ----------------------------------- wk.register({ -- GitSigns g = { name = 'Git', r = 'Reset hunk', s = 'Stage hunk' } }, {mode = 'v', prefix = ''})