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}) -- vim-eft api.nvim_set_keymap('n', 'f', '(eft-f)', {}) api.nvim_set_keymap('x', 'f', '(eft-f)', {}) api.nvim_set_keymap('n', 'F', '(eft-F)', {}) api.nvim_set_keymap('x', 'F', '(eft-F)', {}) api.nvim_set_keymap('n', 't', '(eft-t)', {}) api.nvim_set_keymap('x', 't', '(eft-t)', {}) api.nvim_set_keymap('n', 'T', '(eft-T)', {}) api.nvim_set_keymap('x', 'T', '(eft-T)', {}) api.nvim_set_keymap('n', ';', '(eft-repeat)', {}) api.nvim_set_keymap('x', ';', '(eft-repeat)', {}) ----------------- -- 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'}, [''] = {'q', 'Quit a 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.api.nvim_command('set noexpandtab nosmarttab softtabstop& shiftwidth&') vim.api.nvim_command('echomsg "Switched to indent with tabs"') else vim.opt.expandtab = true vim.opt.smarttab = true vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.api.nvim_command('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', R = {'TroubleToggle lsp_references', 'Reference list'} }, K = {name = 'Hover'}, z = {name = 'Misc utils'}, -- Move between tabs [''] = {'BufferLineCycleNext', 'Next buffer'}, [''] = {'BufferLineCyclePrev', 'Previous buffer'}, -- NvimTree [''] = {':NvimTreeToggle', 'NvimTree'}, -- ToggleTerm [''] = {':ToggleTerm', 'Toggle terminal'}, [''] = {':ToggleTerm direction=float', 'Toggle float terminal'}, -- hop.nvim s = {':HopWord', 'Hop to word'}, S = {':HopChar1', 'Hop to character'}, [''] = {':HopPattern', 'Hop to pattern'} }) ----------------------------------- -- Normal mode (with leader key) -- ----------------------------------- wk.register({ b = { name = 'Buffer', a = {':EasyAlign', 'Easy align'}, c = {':ColorizerToggle', 'Colorizer'}, d = {':bdelete', 'Close buffer'}, j = {':BufferLineCyclePrev', 'Previous buffer'}, k = {':BufferLineCycleNext', 'Next buffer'}, n = {':DashboardNewFile', 'New file'}, u = {':UndotreeToggle', 'Undotree'}, z = {':ZenMode', 'Zen mode'} }, d = { name = 'DAP', b = {':lua require("dap").toggle_breakpoint()', 'Toggle breakpoint'}, c = {':lua require("dapui").close()', 'Close UI'}, e = {':lua require("dapui").eval()', 'Evaluate cursorword'}, f = {':lua require("dapui").float_element()', 'Float elements'}, i = {':lua require("dap").repl.open()', 'Inspect via REPL'}, n = {':lua require("dap").step_into()', 'Step through code'}, o = {':lua require("dapui").open()', 'Open UI'}, s = {':lua require("dap").continue()', 'Debug session'}, t = {':lua require("dapui").open()', 'Toggle UI'} }, -- 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'} }, -- 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'} } }, -- translate-shell.vim j = { name = 'Translate', t = {':Trans', 'Translate'}, d = {':TransSelectDirection', 'Translate with direction'}, r = {'cw=system(\'trans -brief -no-ansi\', getreg(""))[:-2]', 'Translate and replace'}, c = {'cw=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]', 'Translate and replace with direction'} }, l = { name = 'LSP', a = 'Add workspace folder', d = 'Type definition', e = 'Line diagnostics', l = 'Set diagnostics loclist', n = 'Rename in buffer', o = 'Format buffer', r = 'Remove workspace folder', w = 'List workspace folders', x = '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'} }, g = {':SymbolsOutline', 'Symbol outline'}, t = { name = 'Trouble', d = {':TroubleToggle lsp_definitions', 'Definition list'}, e = {':TroubleToggle lsp_document_diagnostics', 'Document diagnostics list'}, w = {':TroubleToggle lsp_workspace_diagnostics', 'Workspace diagnostics list'}, l = {':TroubleToggle loclist', 'Location list items'}, q = {':TroubleToggle quickfix', 'Quickfix list'} } }, n = {':NnnPicker %:p:h', 'File picker'}, s = { name = 'Find/Replace', o = {':lua require("spectre").open()', 'Open spectre'}, p = {'viw:lua require("spectre").open_file_search()', 'Search in current file'}, w = {':lua require("spectre").open_visual({select_word = true})', 'Find/replace cursorword'}, }, -- Tab related t = { name = 'Tab', c = {'tabclose', 'Close tab'}, j = {'tabprev', 'Previous tab'}, k = {'tabnext', 'Next tab'}, n = {'tabnew', 'New tab'} } }, {prefix = ''}) ----------------------------------- -- Visual mode (with leader key) -- ----------------------------------- wk.register({ b = { name = 'Buffer', a = {':EasyAlign', 'Range easy align'} }, d = { name = 'DAP', e = {':lua require("dapui").eval()', 'Evaluate highlighted text'} }, g = { name = 'Git', r = 'Reset hunk', s = 'Stage hunk' }, j = { name = 'Translate', t = {':Trans', 'Translate'}, d = {':TransSelectDirection', 'Translate with direction'}, r = {'c=system(\'trans -brief -no-ansi\', getreg(""))[:-2]', 'Translate and replace'}, c = {'c=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]', 'Translate and replace with direction'} }, s = {':lua require("spectre").open_visual()', 'Find/Replace'} }, {mode = 'v', prefix = ''}) ------------------------ -- Filetype specified -- ------------------------ vim.api.nvim_command [[ autocmd FileType org lua whichkeyOrg() autocmd FileType markdown lua whichkeyMarkdown() autocmd FileType html lua whichkeyHtml() ]] _G.whichkeyOrg = function() wk.register({ ['o'] = { name = 'Org', a = 'Agenda', A = 'Toggle ARCHIVE', c = 'Capture', e = 'Export', i = { name = 'Insert', h = 'Add headline', t = 'Add TODO heading and content', T = 'Add TODO heading', }, J = 'Move subtree down', K = 'Move subtree up', o = 'Open at point', r = 'Refile', t = 'Set tags', ['$'] = 'Archive current headline' }, [''] = 'Org meta return', [''] = 'Org increase date', [''] = 'Org decrease date', ['cid'] = 'Org change date', ['cit'] = 'Org TODO', ['ciT'] = 'Org TODO prev', [''] = 'Org toggle checkbox', [''] = 'Org cycle folding', [''] = 'Org cycle global folding', ['<<'] = 'Org promote headline', ['>>'] = 'Org demote headline', ['s'] = 'Org demote subtree', ['}'] = 'Org next visible heading', ['{'] = 'Org previous visible heading', [']]'] = 'Org forward heading', ['[['] = 'Org backward heading', ['g{'] = 'Org parent heading', ['?'] = 'Org help' }) end _G.whichkeyMarkdown = function() wk.register({ ['bp'] = {':MarkdownPreviewToggle', 'Preview markdown'} }) end _G.whichkeyHtml = function() wk.register({ ['bp'] = {':Bracey', 'Preview html'} }) end