-- see `:help` for any questions -- use `&` to show value of vimscript variable require('keymap/functional') -- API -- local o = vim.o -- options local go = vim.go -- only-global options local bo = vim.bo -- buffer local options local wo = vim.wo -- window local options local cmd = vim.cmd -- vim commands local fn = vim.fn -- vim functions local opt = vim.opt -- vim option object local g = vim.g -- global variables local b = vim.b -- buffer local variables local w = vim.w -- window local variables local t = vim.t -- tab local variables local v = vim.v -- variables local env = vim.env -- environment variables local layouts = { 'qwerty', 'colemak' } local layout = layouts[2] local map = vim.api.nvim_set_keymap local function modes_map(modes) local functions = {} for _,mode in pairs(modes) do table.insert(functions, bind(map,mode)) end return functions end local function keys_modes_map(modes, new_keys, old_keys) for i = 1, #new_keys do for _,f in pairs(modes_map(modes)) do f(new_keys[i], old_keys[i], {noremap = true}) end end end local nvo = {'n','v','o'} if layout == 'qwerty' then -- -- Qwerty: General Bindings -- -- Splits for _,key in pairs({'j','k','l','J','K','L'}) do for _,f in pairs(modes_map({'n', 'v'})) do f('w'..key, ''..key, {noremap = true}) end end -- -- Qwerty: Plugin Bindings -- -- NERDTree defaults vim.g.NERDTreeMapOpenSplit = 'i' -- i vim.g.NERDTreeMapPreviewSplit = 'I' -- gi vim.g.NERDTreeMapJumpFirstChild = 'K' -- K vim.g.NERDTreeMapJumpLastChild = 'J' -- J vim.g.NERDTreeMapJumpNextSibling = '' -- . vim.g.NERDTreeMapJumpPrevSibling = '' -- vim.g.NERDTreeMapChangeRoot = 'l' -- C -- see "All layout" bindings too elseif layout == 'colemak' then -- -- Colemak: General Bindings -- -- Motion -- up(e) down(n) left(h) right(i) keys_modes_map( nvo, {'h','n','e','i'}, {'h','j','k','l'} ) -- word(y) WORD(Y) back(l) BACK(L) end(u) END(U) keys_modes_map( nvo, {'l','L','u','U','y','Y'}, {'b','B','e','E','w','W'} ) -- (a)ppend (r)eplace in(s)ert change(w) keys_modes_map( {'n'}, {'s','S'}, -- see Visual Line Mode Patch {'i','I'} ) keys_modes_map( nvo, {'w','W'}, {'c','C'} ) -- (c)opy (p)aste cut(x,d) keys_modes_map( nvo, {'c','C'}, {'y','Y'} ) -- (u)ndo (r)edo local c_undo_redo = {'z','gz','Z'} keys_modes_map( {'n'}, c_undo_redo, {'u','U','redo' } ) -- Visual Line Mode Patch vim.cmd([[ xnoremap s (mode() =~# "[V]" ? "\0o$I" : "I") xnoremap S (mode() =~# "[V]" ? "\0o$I" : "I") ]]) -- (g)oto -- ge = visual line up -- gn = visual line down keys_modes_map( nvo, {'ge','gn'}, {'gk','gj'} ) -- Search -- (f)ind (F)ind (t)il (T)il next(k) prev(K) keys_modes_map( nvo, {'k','K'}, {'n','N'} ) -- Text Objects -- inner(s) (a) map('o', 's', 'i', {noremap = true}) -- Folds keys_modes_map( {'n','x'}, {'j','jn','je','jo','jc','ja'}, {'z','zn','ze','zo','zc','za'} ) -- Help(B) map('n', 'B', 'K', {noremap = true}) -- Splits local split = { colemak = {'n','e','i','N','E','I'}, qwerty = {'j','k','l','J','K','L'} } for i = 1, #split.colemak do for _,f in pairs(modes_map({'n','v'})) do f('w'..split.colemak[i], ''..split.qwerty[i], {noremap = true}) end end -- Screen / Scroll / Page -- H = top screen -- M = mid screen -- I = bottom screen -- E = half page up -- N = half page down keys_modes_map( {'n','v'}, {'I','E', 'N'}, {'L','',''} ) -- -- Colemak: Plugin Bindings -- -- NERDTree defaults vim.g.NERDTreeMapOpenSplit = 's' -- i vim.g.NERDTreeMapPreviewSplit = 'S' -- gi vim.g.NERDTreeMapJumpFirstChild = 'E' -- K vim.g.NERDTreeMapJumpLastChild = 'N' -- J vim.g.NERDTreeMapJumpNextSibling = '' -- . vim.g.NERDTreeMapJumpPrevSibling = '' -- vim.g.NERDTreeMapChangeRoot = 'i' -- C -- see "All layout" bindings too end -- -- All layouts: General Bindings -- -- Splits for _,key in pairs({'h','H','t','q',''}) do for _,f in pairs(modes_map({'n', 'v'})) do if key ~= 't' then f('w'..key, ''..key, {noremap = true}) else f('wt', 'T', {noremap = true}) end end end -- Search keys_modes_map( {'n','v'}, {'/', '?'}, {'q/i','q?i'} ) -- Remove left over search highlights map('n', '', ':nohlsearch', {noremap = true}) -- Move current line to center of screen map('n', 'm', 'z.', {noremap = true}) -- Buffers local buffer_keys = { new = {'',''}, old = {'n', 'p', 'd'} } for i = 1, #buffer_keys.new do for _,f in pairs(modes_map({'n','v','x'})) do f( ''..buffer_keys.new[i], ':b'..buffer_keys.old[i]..'', {noremap = true} ) end end -- Command mode keys_modes_map( {'n', 'v', 'x'}, {':', ';;', ';e', ';h', ';v'}, {'q:i','q:i!','q:ie term://','q:isp term://','q:ivs term://'} ) -- Filetype specific cmd('autocmd FileType zig lua zig_maps()') function zig_maps() map('n', 'ft', ':vertical !zig test %', {noremap = true}) map('n', 'fr', ':vertical !zig run %', {noremap = true}) end -- -- All layouts: Plugin Bindings -- -- LSP function lsp_shortcuts() local lsp_commands = { new = {'d','r','f','t','x','a','c','C','h','s','m'}, old = { '#textDocument_definition', -- d '#textDocument_rename', -- r '#textDocument_formatting', -- f '#textDocument_typeDefinition', -- t '#textDocument_references', -- x '_workspace_applyEdit', -- a '#textDocument_completion', -- c '#textDocument_codeAction', -- C '#textDocument_hover', -- h '_textDocument_documentSymbol', -- s '_contextMenu' -- m } } for i = 1, #lspcommands.new do for _,f in pairs(modes_map({'n'})) do f('l'..key_pair.new[i], ':call LanguageClient'..key_pair.old[i]..'()', {noremap = true}) end end end -- NERDTree defaults map('n', 'n', ':NERDTree', {noremap = true}) vim.g.NERDTreeMapActivateNode = 'o' -- o vim.g.NERDTreeMapPreview = 'go' -- go vim.g.NERDTreeMapOpenInTab = 't' -- t vim.g.NERDTreeMapOpenInTabSilent = 'T' -- T vim.g.NERDTreeMapOpenVSplit = 'v' -- s vim.g.NERDTreeMapPreviewVSplit = 'V' -- gs vim.g.NERDTreeMapCustomOpen = '' -- vim.g.NERDTreeMapOpenRecursively = 'O' -- O vim.g.NERDTreeMapCloseDir = 'x' -- x vim.g.NERDTreeMapCloseChildren = 'X' -- X vim.g.NERDTreeMapOpenExpl = '' -- e vim.g.NERDTreeMapDeleteBookmark = 'd' -- D vim.g.NERDTreeMapJumpRoot = 'P' -- P vim.g.NERDTreeMapJumpParent = 'p' -- p vim.g.NERDTreeMapUpdir = 'h' -- u vim.g.NERDTreeMapUpdirKeepOpen = 'H' -- U vim.g.NERDTreeMapRefresh = 'r' -- r vim.g.NERDTreeMapRefreshRoot = 'R' -- R vim.g.NERDTreeMapMenu = 'm' -- m vim.g.NERDTreeMapChdir = 'c' -- cd vim.g.NERDTreeMapCWD = 'C' -- CD vim.g.NERDTreeMapToggleHidden = '.' -- I vim.g.NERDTreeMapToggleFilters = 'F' -- f vim.g.NERDTreeMapToggleFiles = 'f' -- F vim.g.NERDTreeMapToggleBookmarks = 'b' -- B vim.g.NERDTreeMapQuit = 'q' -- q vim.g.NERDTreeMapToggleZoom = 'z' -- A vim.g.NERDTreeMapHelp = '?' -- ? -- Limelight map('n', 'ul', ':call LimelightToggle()', {noremap = true}) -- Transparent map('n', 'ut', ':TransparentToggle', {noremap = true})