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)'}, [']'] = {name = 'Block motions (next)'}, g = {name = 'Goto motions'}, 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'}, o = {':Telescope oldfiles', 'Recent files'}, p = {':Telescope man_pages', 'Man pages'}, 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' }, -- Git g = { name = 'Git', b = 'Blame current line', j = 'Next hunk', k = 'Previous hunk', 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 = ''}) ---------------- -- nvim-compe -- ---------------- -- Use (S-)Tab in completion menu -- See https://github.com/L3MON4D3/Luasnip/issues/1#issuecomment-835241958 local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end local function prequire(...) local status, lib = pcall(require, ...) if (status) then return lib end return nil end local luasnip = prequire('luasnip') local check_back_space = function() local col = vim.fn.col('.') - 1 return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil end _G.tab_complete = function() if vim.fn.pumvisible() == 1 then return t '' elseif luasnip and luasnip.expand_or_jumpable() then return t 'luasnip-expand-or-jump' elseif check_back_space() then return t '' else return vim.fn['compe#complete']() end end _G.s_tab_complete = function() if vim.fn.pumvisible() == 1 then return t '' elseif luasnip and luasnip.jumpable(-1) then return t 'luasnip-jump-prev' else return t '' end end vim.api.nvim_set_keymap('i', '', 'v:lua.tab_complete()', {expr = true, noremap = true, silent = true}) vim.api.nvim_set_keymap('s', '', 'v:lua.tab_complete()', {expr = true, noremap = true, silent = true}) vim.api.nvim_set_keymap('i', '', 'v:lua.s_tab_complete()', {expr = true, noremap = true, silent = true}) vim.api.nvim_set_keymap('s', '', 'v:lua.s_tab_complete()', {expr = true, noremap = true, silent = true}) vim.api.nvim_set_keymap('i', '', 'compe#complete()', {expr = true, noremap = true, silent = true}) vim.api.nvim_set_keymap('i', '', 'compe#close(\'\')', {expr = true, noremap = true, silent = true})