From 0deca75ad663c6c114817cbb3ca7ab6d9d87ab07 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 10 May 2022 00:01:45 +0900 Subject: neovim: refactor keymapping --- .config/nvim/init.lua | 527 ++++++++++++++++++++++----------------------- .config/nvim/lua/vimrc.lua | 69 ------ 2 files changed, 255 insertions(+), 341 deletions(-) (limited to '.config') diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 8ffe9bd..ffc42b4 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -292,152 +292,145 @@ vimrc.register_filetype_autocmds_for_indentation() -- Searching {{{2 -- Fix direction of n and N. -vimrc.map('', 'n', "v:searchforward ? 'n' : 'N'", { expr = true }) -vimrc.map('', 'N', "v:searchforward ? 'N' : 'n'", { expr = true }) +vim.keymap.set('', 'n', "v:searchforward ? 'n' : 'N'", { expr=true }) +vim.keymap.set('', 'N', "v:searchforward ? 'N' : 'n'", { expr=true }) -vimrc.map('', 'gn', "v:searchforward ? 'gn' : 'gN'", { expr = true }) -vimrc.map('', 'gN', "v:searchforward ? 'gN' : 'gn'", { expr = true }) +vim.keymap.set('', 'gn', "v:searchforward ? 'gn' : 'gN'", { expr=true }) +vim.keymap.set('', 'gN', "v:searchforward ? 'gN' : 'gn'", { expr=true }) -vimrc.map('n', '&', ':%&&', { silent = true }) -vimrc.map('x', '&', ':%&&', { silent = true }) +vim.keymap.set({'n', 'x'}, '&', '%&&') -- Registers and macros. {{{2 -- Access an resister in the same way in Insert and Commandline mode. -vimrc.map('n', '', '"') -vimrc.map('x', '', '"') +vim.keymap.set({'n', 'x'}, '', '"') F.setreg('j', 'j.') F.setreg('k', 'k.') F.setreg('n', 'n.') F.setreg('m', 'N.') -vimrc.map('n', '@N', '@m') +vim.keymap.set('n', '@N', '@m') -- Repeat the last executed macro as many times as possible. -- a => all -vimrc.map('n', '@a', '9999@@') -vimrc.map('n', '@a', '9999@@') +vim.keymap.set('n', '@a', '9999@@') -- Execute the last executed macro again. -vimrc.map('n', '`', '@@') +vim.keymap.set('n', '`', '@@') -- Emacs like key mappings in Insert and CommandLine mode. {{{2 -vimrc.map('i', '', '') +vim.keymap.set('i', '', '') -- Go elsewhere without deviding the undo history. -vimrc.map('i', '', "repeat('U', col('.') - 1)", { expr = true }) -vimrc.map('i', '', "repeat('U', col('$') - col('.'))", { expr = true }) -vimrc.map('i', '', 'U') -vimrc.map('i', '', 'U') +vim.keymap.set('i', '', "repeat('U', col('.') - 1)", { expr=true }) +vim.keymap.set('i', '', "repeat('U', col('$') - col('.'))", { expr=true }) +vim.keymap.set('i', '', 'U') +vim.keymap.set('i', '', 'U') -- Delete something deviding the undo history. -vimrc.map('i', '', 'u') -vimrc.map('i', '', 'u') +vim.keymap.set('i', '', 'u') +vim.keymap.set('i', '', 'u') -vimrc.map('c', '', '') -vimrc.map('c', '', '') -vimrc.map('c', '', '') -vimrc.map('c', '', '') -vimrc.map('c', '', '') -vimrc.map('c', '', '') -vimrc.map('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') +vim.keymap.set('c', '', '') -vimrc.map('c', '', '') -vimrc.map('i', '', '') -vimrc.map('c', '', '') -vimrc.map('i', '', '') +vim.keymap.set({'c', 'i'}, '', '') +vim.keymap.set({'c', 'i'}, '', '') -vimrc.map_expr('n', 'gA', function() +vim.keymap.set('n', 'gA', function() local line = F.getline('.') if vim.endswith(line, ';;') then -- for OCaml - return vimrc.term([[AUU]]) + return 'AUU' elseif vim.regex('[,;)]$'):match_str(line) then - return vimrc.term([[AU]]) + return 'AU' else return 'A' end -end) +end, { expr=true, replace_keycodes=true }) -- QuickFix or location list. {{{2 -vimrc.map_cmd('n', 'bb', 'cc') +vim.keymap.set('n', 'bb', 'cc') -vimrc.map('n', 'bn', ':=v:count1cnext', { silent = true }) -vimrc.map('n', 'bp', ':=v:count1cprevious', { silent = true }) +vim.keymap.set('n', 'bn', ':=v:count1cnext', { silent = true }) +vim.keymap.set('n', 'bp', ':=v:count1cprevious', { silent = true }) -vimrc.map_cmd('n', 'bf', 'cfirst') -vimrc.map_cmd('n', 'bl', 'clast') +vim.keymap.set('n', 'bf', 'cfirst') +vim.keymap.set('n', 'bl', 'clast') -vimrc.map_cmd('n', 'bS', 'colder') -vimrc.map_cmd('n', 'bs', 'cnewer') +vim.keymap.set('n', 'bS', 'colder') +vim.keymap.set('n', 'bs', 'cnewer') -- Operators {{{2 -- Throw deleted text into the black hole register ("_). -vimrc.map('n', 'c', '"_c') -vimrc.map('x', 'c', '"_c') -vimrc.map('n', 'C', '"_C') -vimrc.map('x', 'C', '"_C') +vim.keymap.set({'n', 'x'}, 'c', '"_c') +vim.keymap.set({'n', 'x'}, 'C', '"_C') -vimrc.map('', 'g=', '=') +vim.keymap.set('', 'g=', '=') -vimrc.map('', 'ml', 'gu') -vimrc.map('', 'mu', 'gU') +vim.keymap.set('', 'ml', 'gu') +vim.keymap.set('', 'mu', 'gU') -vimrc.map('', 'gu', '') -vimrc.map('', 'gU', '') -vimrc.map('x', 'u', '') -vimrc.map('x', 'U', '') +vim.keymap.set('', 'gu', '') +vim.keymap.set('', 'gU', '') +vim.keymap.set('x', 'u', '') +vim.keymap.set('x', 'U', '') -vimrc.map('x', 'x', '"_x') +vim.keymap.set('x', 'x', '"_x') -vimrc.map('n', 'Y', 'y$') +vim.keymap.set('n', 'Y', 'y$') -- In Blockwise-Visual mode, select text linewise. -- By default, select text characterwise, neither blockwise nor linewise. -vimrc.map('x', 'Y', "mode() ==# 'V' ? 'y' : 'Vy'", { expr = true }) +vim.keymap.set('x', 'Y', "mode() ==# 'V' ? 'y' : 'Vy'", { expr=true }) -- Swap the keys entering Replace mode and Visual-Replace mode. -vimrc.map('n', 'R', 'gR') -vimrc.map('n', 'gR', 'R') -vimrc.map('n', 'r', 'gr') -vimrc.map('n', 'gr', 'r') +vim.keymap.set('n', 'R', 'gR') +vim.keymap.set('n', 'gR', 'R') +vim.keymap.set('n', 'r', 'gr') +vim.keymap.set('n', 'gr', 'r') -vimrc.map('n', 'U', '') +vim.keymap.set('n', 'U', '') -- Motions {{{2 -vimrc.map('', 'H', '^') -vimrc.map('', 'L', '$') -vimrc.map('', 'M', '%') +vim.keymap.set('', 'H', '^') +vim.keymap.set('', 'L', '$') +vim.keymap.set('', 'M', '%') -vimrc.map('', 'gw', 'b') -vimrc.map('', 'gW', 'B') +vim.keymap.set('', 'gw', 'b') +vim.keymap.set('', 'gW', 'B') -vimrc.map('', 'k', 'gk') -vimrc.map('', 'j', 'gj') -vimrc.map('', 'gk', 'k') -vimrc.map('', 'gj', 'j') +vim.keymap.set('', 'k', 'gk') +vim.keymap.set('', 'j', 'gj') +vim.keymap.set('', 'gk', 'k') +vim.keymap.set('', 'gj', 'j') -vimrc.map('n', 'gff', 'gF') +vim.keymap.set('n', 'gff', 'gF') @@ -457,15 +450,6 @@ function vimrc.fn.move_current_window_to_tabpage() end -function vimrc.fn.bdelete_bang_with_confirm() - if string.lower(vimrc.getchar_with_prompt('Delete? (y/n) ')) == 'y' then - vim.cmd('bdelete!') - else - vimrc.echo('Canceled') - end -end - - function vimrc.fn.choose_window_interactively() local indicators = { 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', @@ -548,64 +532,63 @@ function vimrc.fn.choose_window_interactively() end -vimrc.map('n', 'tt', ':tabnew', { silent = true }) -vimrc.map('n', 'tT', ':call v:lua.vimrc.fn.move_current_window_to_tabpage()', { silent = true }) +vim.keymap.set('n', 'tt', 'tabnew') +vim.keymap.set('n', 'tT', vimrc.fn.move_current_window_to_tabpage) -vimrc.map('n', 'tn', ":=(tabpagenr() + v:count1 - 1) % tabpagenr('$') + 1tabnext", { silent = true }) -vimrc.map('n', 'tp', ":=(tabpagenr('$') * 10 + tabpagenr() - v:count1 - 1) % tabpagenr('$') + 1tabnext", { silent = true }) +vim.keymap.set('n', 'tn', ":=(tabpagenr() + v:count1 - 1) % tabpagenr('$') + 1tabnext", { silent=true }) +vim.keymap.set('n', 'tp', ":=(tabpagenr('$') * 10 + tabpagenr() - v:count1 - 1) % tabpagenr('$') + 1tabnext", { silent=true }) -vimrc.map('n', 'tN', ':tabmove +', { silent = true }) -vimrc.map('n', 'tP', ':tabmove -', { silent = true }) +vim.keymap.set('n', 'tN', 'tabmove +') +vim.keymap.set('n', 'tP', 'tabmove -') -vimrc.map('n', 'tsh', ':leftabove vsplit', { silent = true }) -vimrc.map('n', 'tsj', ':rightbelow split', { silent = true }) -vimrc.map('n', 'tsk', ':leftabove split', { silent = true }) -vimrc.map('n', 'tsl', ':rightbelow vsplit', { silent = true }) +vim.keymap.set('n', 'tsh', 'leftabove vsplit') +vim.keymap.set('n', 'tsj', 'rightbelow split') +vim.keymap.set('n', 'tsk', 'leftabove split') +vim.keymap.set('n', 'tsl', 'rightbelow vsplit') -vimrc.map('n', 'tsH', ':topleft vsplit', { silent = true }) -vimrc.map('n', 'tsJ', ':botright split', { silent = true }) -vimrc.map('n', 'tsK', ':topleft split', { silent = true }) -vimrc.map('n', 'tsL', ':botright vsplit', { silent = true }) +vim.keymap.set('n', 'tsH', 'topleft vsplit') +vim.keymap.set('n', 'tsJ', 'botright split') +vim.keymap.set('n', 'tsK', 'topleft split') +vim.keymap.set('n', 'tsL', 'botright vsplit') -vimrc.map('n', 'twh', ':leftabove vnew', { silent = true }) -vimrc.map('n', 'twj', ':rightbelow new', { silent = true }) -vimrc.map('n', 'twk', ':leftabove new', { silent = true }) -vimrc.map('n', 'twl', ':rightbelow vnew', { silent = true }) +vim.keymap.set('n', 'twh', 'leftabove vnew') +vim.keymap.set('n', 'twj', 'rightbelow new') +vim.keymap.set('n', 'twk', 'leftabove new') +vim.keymap.set('n', 'twl', 'rightbelow vnew') -vimrc.map('n', 'twH', ':topleft vnew', { silent = true }) -vimrc.map('n', 'twJ', ':botright new', { silent = true }) -vimrc.map('n', 'twK', ':topleft new', { silent = true }) -vimrc.map('n', 'twL', ':botright vnew', { silent = true }) +vim.keymap.set('n', 'twH', 'topleft vnew') +vim.keymap.set('n', 'twJ', 'botright new') +vim.keymap.set('n', 'twK', 'topleft new') +vim.keymap.set('n', 'twL', 'botright vnew') -vimrc.map('n', 'th', 'h') -vimrc.map('n', 'tj', 'j') -vimrc.map('n', 'tk', 'k') -vimrc.map('n', 'tl', 'l') +vim.keymap.set('n', 'th', 'h') +vim.keymap.set('n', 'tj', 'j') +vim.keymap.set('n', 'tk', 'k') +vim.keymap.set('n', 'tl', 'l') -vimrc.map('n', 'tH', 'H') -vimrc.map('n', 'tJ', 'J') -vimrc.map('n', 'tK', 'K') -vimrc.map('n', 'tL', 'L') +vim.keymap.set('n', 'tH', 'H') +vim.keymap.set('n', 'tJ', 'J') +vim.keymap.set('n', 'tK', 'K') +vim.keymap.set('n', 'tL', 'L') -vimrc.map('n', 'tx', 'x') +vim.keymap.set('n', 'tx', 'x') -- r => manual resize. -- R => automatic resize. -vimrc.map('n', 'tRH', '_') -vimrc.map('n', 'tRW', '') -vimrc.map('n', 'tRR', '_') +vim.keymap.set('n', 'tRH', '_') +vim.keymap.set('n', 'tRW', '') +vim.keymap.set('n', 'tRR', '_') -vimrc.map('n', 't=', '=') +vim.keymap.set('n', 't=', '=') -vimrc.map('n', 'tq', ':bdelete', { silent = true }) -vimrc.map('n', 'tQ', ':call v:lua.vimrc.fn.bdelete_bang_with_confirm()', { silent = true }) +vim.keymap.set('n', 'tq', 'bdelete') -vimrc.map('n', 'tc', 'c') +vim.keymap.set('n', 'tc', 'c') -vimrc.map('n', 'to', 'o') -vimrc.map('n', 'tO', ':tabonly', { silent = true }) +vim.keymap.set('n', 'to', 'o') +vim.keymap.set('n', 'tO', 'tabonly') -vimrc.map('n', 'tg', ':call v:lua.vimrc.fn.choose_window_interactively()', { silent = true }) +vim.keymap.set('n', 'tg', vimrc.fn.choose_window_interactively) @@ -659,30 +642,30 @@ vim.api.nvim_create_user_command( -- Toggle options {{{2 -vimrc.map('n', 'T', '') - -vimrc.map('n', 'Ta', ':AutosaveToggle', { silent = true }) -vimrc.map('n', 'Tb', ':if &background == "dark" set background=light else set background=dark endif', { silent = true }) -vimrc.map('n', 'Tc', ':set cursorcolumn! set cursorline!', { silent = true }) -vimrc.map('n', 'Td', ':if &diff diffoff else diffthis endif', { silent = true }) -vimrc.map('n', 'Te', ':set expandtab!', { silent = true }) -vimrc.map('n', 'Th', ':set hlsearch!', { silent = true }) -vimrc.map('n', 'Tn', ':set number!', { silent = true }) -vimrc.map('n', 'Ts', ':set spell!', { silent = true }) -vimrc.map('n', 'T8', ':if &textwidth ==# 80 set textwidth=0 else set textwidth=80 endif', { silent = true }) -vimrc.map('n', 'T0', ':if &textwidth ==# 100 set textwidth=0 else set textwidth=100 endif', { silent = true }) -vimrc.map('n', 'T2', ':if &textwidth ==# 120 set textwidth=0 else set textwidth=120 endif', { silent = true }) -vimrc.map('n', 'Tw', ':set wrap!', { silent = true }) - -vimrc.remap('n', 'TA', 'Ta') -vimrc.remap('n', 'TB', 'Tb') -vimrc.remap('n', 'TC', 'Tc') -vimrc.remap('n', 'TD', 'Td') -vimrc.remap('n', 'TE', 'Te') -vimrc.remap('n', 'TH', 'Th') -vimrc.remap('n', 'TN', 'Tn') -vimrc.remap('n', 'TS', 'Ts') -vimrc.remap('n', 'TW', 'Tw') +vim.keymap.set('n', 'T', '') + +vim.keymap.set('n', 'Ta', 'AutosaveToggle') +vim.keymap.set('n', 'Tb', ':if &background == "dark" set background=light else set background=dark endif', { silent=true }) +vim.keymap.set('n', 'Tc', ':set cursorcolumn! set cursorline!', { silent=true }) +vim.keymap.set('n', 'Td', ':if &diff diffoff else diffthis endif', { silent=true }) +vim.keymap.set('n', 'Te', 'set expandtab!') +vim.keymap.set('n', 'Th', 'set hlsearch!') +vim.keymap.set('n', 'Tn', 'set number!') +vim.keymap.set('n', 'Ts', 'set spell!') +vim.keymap.set('n', 'T8', ':if &textwidth ==# 80 set textwidth=0 else set textwidth=80 endif', { silent=true }) +vim.keymap.set('n', 'T0', ':if &textwidth ==# 100 set textwidth=0 else set textwidth=100 endif', { silent=true }) +vim.keymap.set('n', 'T2', ':if &textwidth ==# 120 set textwidth=0 else set textwidth=120 endif', { silent=true }) +vim.keymap.set('n', 'Tw', 'set wrap!') + +vim.keymap.set('n', 'TA', 'Ta', { remap=true }) +vim.keymap.set('n', 'TB', 'Tb', { remap=true }) +vim.keymap.set('n', 'TC', 'Tc', { remap=true }) +vim.keymap.set('n', 'TD', 'Td', { remap=true }) +vim.keymap.set('n', 'TE', 'Te', { remap=true }) +vim.keymap.set('n', 'TH', 'Th', { remap=true }) +vim.keymap.set('n', 'TN', 'Tn', { remap=true }) +vim.keymap.set('n', 'TS', 'Ts', { remap=true }) +vim.keymap.set('n', 'TW', 'Tw', { remap=true }) @@ -744,40 +727,40 @@ vim.api.nvim_create_user_command( } ) -vimrc.map('n', 's', 'Scratch', { silent = true }) +vim.keymap.set('n', 's', 'Scratch') -- Disable unuseful or dangerous mappings. {{{2 -- Disable Select mode. -vimrc.map('n', 'gh', '') -vimrc.map('n', 'gH', '') -vimrc.map('n', 'g', '') +vim.keymap.set('n', 'gh', '') +vim.keymap.set('n', 'gH', '') +vim.keymap.set('n', 'g', '') -- Disable Ex mode. -vimrc.map('n', 'Q', '') -vimrc.map('n', 'gQ', '') +vim.keymap.set('n', 'Q', '') +vim.keymap.set('n', 'gQ', '') -vimrc.map('n', 'ZZ', '') -vimrc.map('n', 'ZQ', '') +vim.keymap.set('n', 'ZZ', '') +vim.keymap.set('n', 'ZQ', '') -- Help {{{2 -- Search help. -vimrc.map('n', '', ':SmartOpen help') +vim.keymap.set('n', '', ':SmartOpen help') -- For writing Vim script. {{{2 -vimrc.map('n', 'XV', ':SmartTabEdit $MYVIMRC', { silent = true }) +vim.keymap.set('n', 'XV', 'SmartTabEdit $MYVIMRC') -- See |numbered-function|. -vimrc.map('n', 'XF', ':function {=v:count}', { silent = true }) +vim.keymap.set('n', 'XF', ':function {=v:count}', { silent=true }) -vimrc.map('n', 'XM', ':messages', { silent = true }) +vim.keymap.set('n', 'XM', 'messages') @@ -796,25 +779,25 @@ vimrc.iabbrev('tihs', 'this') -- Misc. {{{2 -vimrc.map('o', 'gv', ':normal! gv', { silent = true }) +vim.keymap.set('o', 'gv', ':normal! gv', { silent=true }) -- Swap : and ;. -vimrc.map('n', ';', ':') -vimrc.map('n', ':', ';') -vimrc.map('x', ';', ':') -vimrc.map('x', ':', ';') -vimrc.map('n', '@;', '@:') -vimrc.map('x', '@;', '@:') -vimrc.map('!', ';', ':') +vim.keymap.set('n', ';', ':') +vim.keymap.set('n', ':', ';') +vim.keymap.set('x', ';', ':') +vim.keymap.set('x', ':', ';') +vim.keymap.set('n', '@;', '@:') +vim.keymap.set('x', '@;', '@:') +vim.keymap.set('!', ';', ':') -- Since may be mapped to something else somewhere, it should be :map, not -- :noremap. -vimrc.remap('!', 'jk', '') +vim.keymap.set('!', 'jk', '', { remap=true }) -vimrc.map('n', '', ':nohlsearch', { silent = true }) +vim.keymap.set('n', '', ':nohlsearch', { silent=true }) @@ -824,23 +807,23 @@ function vimrc.map_callbacks.insert_blank_line(offset) end end -vimrc.map('n', '(my-insert-blank-lines-after)', +vim.keymap.set('n', '(my-insert-blank-lines-after)', 'call v:lua.vimrc.map_callbacks.insert_blank_line(0)') -vimrc.map('n', '(my-insert-blank-lines-before)', +vim.keymap.set('n', '(my-insert-blank-lines-before)', 'call v:lua.vimrc.map_callbacks.insert_blank_line(1)') -vimrc.map_plug('n', 'go', '(my-insert-blank-lines-after)') -vimrc.map_plug('n', 'gO', '(my-insert-blank-lines-before)') +vim.keymap.set('n', 'go', '(my-insert-blank-lines-after)') +vim.keymap.set('n', 'gO', '(my-insert-blank-lines-before)') -vimrc.map('n', 'w', 'update') +vim.keymap.set('n', 'w', 'update') -vimrc.map('n', 'Z', 'wqall', { nowait = true }) +vim.keymap.set('n', 'Z', 'wqall', { nowait = true }) -- `s` is used as a prefix key of plugin sandwich and hop. -vimrc.map('n', 's', '') -vimrc.map('x', 's', '') +vim.keymap.set('n', 's', '') +vim.keymap.set('x', 's', '') -- Commands {{{1 @@ -1274,7 +1257,7 @@ F['altr#define']('%.c', '%.cpp', '%.cc', '%.h', '%.hh', '%.hpp') F['altr#define']('autoload/%.vim', 'doc/%.txt', 'plugin/%.vim') -- Go to File Alternative -vimrc.map_plug('n', 'gfa', '(altr-forward)') +vim.keymap.set('n', 'gfa', '(altr-forward)') @@ -1316,14 +1299,14 @@ xmap g# My_asterisk('(asterisk-gz*)', 1) G.caw_no_default_keymappings = true -vimrc.map_plug('n', 'm//', '(caw:hatpos:toggle)') -vimrc.map_plug('x', 'm//', '(caw:hatpos:toggle)') -vimrc.map_plug('n', 'm/w', '(caw:wrap:comment)') -vimrc.map_plug('x', 'm/w', '(caw:wrap:comment)') -vimrc.map_plug('n', 'm/W', '(caw:wrap:uncomment)') -vimrc.map_plug('x', 'm/W', '(caw:wrap:uncomment)') -vimrc.map_plug('n', 'm/b', '(caw:box:comment)') -vimrc.map_plug('x', 'm/b', '(caw:box:comment)') +vim.keymap.set('n', 'm//', '(caw:hatpos:toggle)') +vim.keymap.set('x', 'm//', '(caw:hatpos:toggle)') +vim.keymap.set('n', 'm/w', '(caw:wrap:comment)') +vim.keymap.set('x', 'm/w', '(caw:wrap:comment)') +vim.keymap.set('n', 'm/W', '(caw:wrap:uncomment)') +vim.keymap.set('x', 'm/W', '(caw:wrap:uncomment)') +vim.keymap.set('n', 'm/b', '(caw:box:comment)') +vim.keymap.set('x', 'm/b', '(caw:box:comment)') @@ -1361,8 +1344,8 @@ end -- easyalign {{{2 -vimrc.map_plug('n', '=', '(EasyAlign)') -vimrc.map_plug('x', '=', '(EasyAlign)') +vim.keymap.set('n', '=', '(EasyAlign)') +vim.keymap.set('x', '=', '(EasyAlign)') @@ -1514,47 +1497,47 @@ function vimrc.map_callbacks.hop_jk(opts) ) end -vimrc.map('', '(hop-f)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true })", { silent = true }) -vimrc.map('', '(hop-F)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true })", { silent = true }) -vimrc.map('', '(hop-t)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true })", { silent = true }) -vimrc.map('', '(hop-T)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true })", { silent = true }) - -vimrc.map('', '(hop-s2)', "lua require('hop').hint_char2()", { silent = true }) -vimrc.map('', '(hop-n)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.AFTER_CURSOR }, vim.fn.getreg('/'))", { silent = true }) -vimrc.map('', '(hop-N)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR }, vim.fn.getreg('/'))", { silent = true }) -vimrc.map('', '(hop-j)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.AFTER_CURSOR })", { silent = true }) -vimrc.map('', '(hop-k)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR })", { silent = true }) - -vimrc.map_plug('n', 'f', '(hop-f)') -vimrc.map_plug('o', 'f', '(hop-f)') -vimrc.map_plug('x', 'f', '(hop-f)') -vimrc.map_plug('n', 'F', '(hop-F)') -vimrc.map_plug('o', 'F', '(hop-F)') -vimrc.map_plug('x', 'F', '(hop-F)') -vimrc.map_plug('o', 't', '(hop-t)') -vimrc.map_plug('x', 't', '(hop-t)') -vimrc.map_plug('o', 'T', '(hop-T)') -vimrc.map_plug('x', 'T', '(hop-T)') +vim.keymap.set('', '(hop-f)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true })", { silent=true }) +vim.keymap.set('', '(hop-F)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true })", { silent=true }) +vim.keymap.set('', '(hop-t)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.AFTER_CURSOR, current_line_only = true })", { silent=true }) +vim.keymap.set('', '(hop-T)', "lua require('hop').hint_char1({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR, current_line_only = true })", { silent=true }) + +vim.keymap.set('', '(hop-s2)', "lua require('hop').hint_char2()", { silent=true }) +vim.keymap.set('', '(hop-n)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.AFTER_CURSOR }, vim.fn.getreg('/'))", { silent=true }) +vim.keymap.set('', '(hop-N)', "lua require('hop').hint_patterns({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR }, vim.fn.getreg('/'))", { silent=true }) +vim.keymap.set('', '(hop-j)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.AFTER_CURSOR })", { silent=true }) +vim.keymap.set('', '(hop-k)', "lua vimrc.map_callbacks.hop_jk({ direction = require('hop.hint').HintDirection.BEFORE_CURSOR })", { silent=true }) + +vim.keymap.set('n', 'f', '(hop-f)') +vim.keymap.set('o', 'f', '(hop-f)') +vim.keymap.set('x', 'f', '(hop-f)') +vim.keymap.set('n', 'F', '(hop-F)') +vim.keymap.set('o', 'F', '(hop-F)') +vim.keymap.set('x', 'F', '(hop-F)') +vim.keymap.set('o', 't', '(hop-t)') +vim.keymap.set('x', 't', '(hop-t)') +vim.keymap.set('o', 'T', '(hop-T)') +vim.keymap.set('x', 'T', '(hop-T)') -- Note: Don't use the following key sequences! It is used 'vim-sandwich'. -- * sa -- * sd -- * sr -vimrc.map_plug('n', 'ss', '(hop-s2)') -vimrc.map_plug('o', 'ss', '(hop-s2)') -vimrc.map_plug('x', 'ss', '(hop-s2)') -vimrc.map_plug('n', 'sn', '(hop-n)') -vimrc.map_plug('o', 'sn', '(hop-n)') -vimrc.map_plug('x', 'sn', '(hop-n)') -vimrc.map_plug('n', 'sN', '(hop-N)') -vimrc.map_plug('o', 'sN', '(hop-N)') -vimrc.map_plug('x', 'sN', '(hop-N)') -vimrc.map_plug('n', 'sj', '(hop-j)') -vimrc.map_plug('o', 'sj', '(hop-j)') -vimrc.map_plug('x', 'sj', '(hop-j)') -vimrc.map_plug('n', 'sk', '(hop-k)') -vimrc.map_plug('o', 'sk', '(hop-k)') -vimrc.map_plug('x', 'sk', '(hop-k)') +vim.keymap.set('n', 'ss', '(hop-s2)') +vim.keymap.set('o', 'ss', '(hop-s2)') +vim.keymap.set('x', 'ss', '(hop-s2)') +vim.keymap.set('n', 'sn', '(hop-n)') +vim.keymap.set('o', 'sn', '(hop-n)') +vim.keymap.set('x', 'sn', '(hop-n)') +vim.keymap.set('n', 'sN', '(hop-N)') +vim.keymap.set('o', 'sN', '(hop-N)') +vim.keymap.set('x', 'sN', '(hop-N)') +vim.keymap.set('n', 'sj', '(hop-j)') +vim.keymap.set('o', 'sj', '(hop-j)') +vim.keymap.set('x', 'sj', '(hop-j)') +vim.keymap.set('n', 'sk', '(hop-k)') +vim.keymap.set('o', 'sk', '(hop-k)') +vim.keymap.set('x', 'sk', '(hop-k)') @@ -1578,10 +1561,10 @@ G['jplus#input_config'] = { L = { delimiter_format = '' }, } -vimrc.map_plug('n', 'J', '(jplus-getchar)') -vimrc.map_plug('x', 'J', '(jplus-getchar)') -vimrc.map_plug('n', 'gJ', '(jplus-input)') -vimrc.map_plug('x', 'gJ', '(jplus-input)') +vim.keymap.set('n', 'J', '(jplus-getchar)') +vim.keymap.set('x', 'J', '(jplus-getchar)') +vim.keymap.set('n', 'gJ', '(jplus-input)') +vim.keymap.set('x', 'gJ', '(jplus-input)') @@ -1593,9 +1576,9 @@ vimrc.map_plug('x', 'gJ', '(jplus-input)') -- niceblock {{{2 -vimrc.map_plug('x', 'I', '(niceblock-I)') -vimrc.map_plug('x', 'gI', '(niceblock-gI)') -vimrc.map_plug('x', 'A', '(niceblock-A)') +vim.keymap.set('x', 'I', '(niceblock-I)') +vim.keymap.set('x', 'gI', '(niceblock-gI)') +vim.keymap.set('x', 'A', '(niceblock-A)') @@ -1604,24 +1587,24 @@ vimrc.map_plug('x', 'A', '(niceblock-A)') -- operator-replace {{{2 -vimrc.map_plug('n', '', '(operator-replace)') -vimrc.map_plug('o', '', '(operator-replace)') -vimrc.map_plug('x', '', '(operator-replace)') +vim.keymap.set('n', '', '(operator-replace)') +vim.keymap.set('o', '', '(operator-replace)') +vim.keymap.set('x', '', '(operator-replace)') -- operator-search {{{2 -- Note: m/ is the prefix of comment out. -vimrc.map_plug('n', 'm?', '(operator-search)') -vimrc.map_plug('o', 'm?', '(operator-search)') -vimrc.map_plug('x', 'm?', '(operator-search)') +vim.keymap.set('n', 'm?', '(operator-search)') +vim.keymap.set('o', 'm?', '(operator-search)') +vim.keymap.set('x', 'm?', '(operator-search)') -- qfreplace {{{2 -vimrc.map('n', 'br', ':Qfreplace SmartOpen', { silent = true }) +vim.keymap.set('n', 'br', ':Qfreplace SmartOpen', { silent=true }) @@ -1641,9 +1624,9 @@ G.quickhl_manual_colors = { 'guifg=#101020 guibg=#ffffa0 gui=bold', } -vimrc.map_plug('n', '"', '(quickhl-manual-this)') -vimrc.map_plug('x', '"', '(quickhl-manual-this)') -vimrc.map('n', '', ':nohlsearch QuickhlManualReset', { silent = true }) +vim.keymap.set('n', '"', '(quickhl-manual-this)') +vim.keymap.set('x', '"', '(quickhl-manual-this)') +vim.keymap.set('n', '', ':nohlsearch QuickhlManualReset', { silent=true }) @@ -1667,15 +1650,15 @@ G.quickrun_config = { } -vimrc.map_plug('n', 'BB', '(quickrun)') -vimrc.map_plug('x', 'BB', '(quickrun)') +vim.keymap.set('n', 'BB', '(quickrun)') +vim.keymap.set('x', 'BB', '(quickrun)') -- repeat {{{2 -vimrc.map_plug('n', 'U', '(RepeatRedo)') +vim.keymap.set('n', 'U', '(RepeatRedo)') -- Autoload vim-repeat immediately in order to make (RepeatRedo) available. -- repeat#setreg() does nothing here. F['repeat#setreg']('', '') @@ -1796,10 +1779,10 @@ G.swap_no_default_key_mappings = true G.textobj_continuous_line_no_default_key_mappings = true -vimrc.map_plug('o', 'aL', '(textobj-continuous-cpp-a)') -vimrc.map_plug('x', 'aL', '(textobj-continuous-cpp-a)') -vimrc.map_plug('o', 'iL', '(textobj-continuous-cpp-i)') -vimrc.map_plug('x', 'iL', '(textobj-continuous-cpp-i)') +vim.keymap.set('o', 'aL', '(textobj-continuous-cpp-a)') +vim.keymap.set('x', 'aL', '(textobj-continuous-cpp-a)') +vim.keymap.set('o', 'iL', '(textobj-continuous-cpp-i)') +vim.keymap.set('x', 'iL', '(textobj-continuous-cpp-i)') vimrc.autocmd('FileType', { pattern = 'vim', @@ -1824,10 +1807,10 @@ vimrc.autocmd('FileType', { G.textobj_lastpaste_no_default_key_mappings = true -vimrc.map_plug('o', 'iP', '(textobj-lastpaste-i)') -vimrc.map_plug('x', 'iP', '(textobj-lastpaste-i)') -vimrc.map_plug('o', 'aP', '(textobj-lastpaste-a)') -vimrc.map_plug('x', 'aP', '(textobj-lastpaste-a)') +vim.keymap.set('o', 'iP', '(textobj-lastpaste-i)') +vim.keymap.set('x', 'iP', '(textobj-lastpaste-i)') +vim.keymap.set('o', 'aP', '(textobj-lastpaste-a)') +vim.keymap.set('x', 'aP', '(textobj-lastpaste-a)') @@ -1835,33 +1818,33 @@ vimrc.map_plug('x', 'aP', '(textobj-lastpaste-a)') G.textobj_space_no_default_key_mappings = true -vimrc.map_plug('o', 'a', '(textobj-space-a)') -vimrc.map_plug('x', 'a', '(textobj-space-a)') -vimrc.map_plug('o', 'i', '(textobj-space-i)') -vimrc.map_plug('x', 'i', '(textobj-space-i)') +vim.keymap.set('o', 'a', '(textobj-space-a)') +vim.keymap.set('x', 'a', '(textobj-space-a)') +vim.keymap.set('o', 'i', '(textobj-space-i)') +vim.keymap.set('x', 'i', '(textobj-space-i)') -- textobj-wiw {{{2 G.textobj_wiw_no_default_key_mappings = true -vimrc.map_plug('n', '', '(textobj-wiw-n)') -vimrc.map_plug('o', '', '(textobj-wiw-n)') -vimrc.map_plug('x', '', '(textobj-wiw-n)') -vimrc.map_plug('n', 'g', '(textobj-wiw-p)') -vimrc.map_plug('o', 'g', '(textobj-wiw-p)') -vimrc.map_plug('x', 'g', '(textobj-wiw-p)') -vimrc.map_plug('n', '', '(textobj-wiw-N)') -vimrc.map_plug('o', '', '(textobj-wiw-N)') -vimrc.map_plug('x', '', '(textobj-wiw-N)') -vimrc.map_plug('n', 'g', '(textobj-wiw-P)') -vimrc.map_plug('o', 'g', '(textobj-wiw-P)') -vimrc.map_plug('x', 'g', '(textobj-wiw-P)') +vim.keymap.set('n', '', '(textobj-wiw-n)') +vim.keymap.set('o', '', '(textobj-wiw-n)') +vim.keymap.set('x', '', '(textobj-wiw-n)') +vim.keymap.set('n', 'g', '(textobj-wiw-p)') +vim.keymap.set('o', 'g', '(textobj-wiw-p)') +vim.keymap.set('x', 'g', '(textobj-wiw-p)') +vim.keymap.set('n', '', '(textobj-wiw-N)') +vim.keymap.set('o', '', '(textobj-wiw-N)') +vim.keymap.set('x', '', '(textobj-wiw-N)') +vim.keymap.set('n', 'g', '(textobj-wiw-P)') +vim.keymap.set('o', 'g', '(textobj-wiw-P)') +vim.keymap.set('x', 'g', '(textobj-wiw-P)') -vimrc.map_plug('o', 'a', '(textobj-wiw-a)') -vimrc.map_plug('x', 'a', '(textobj-wiw-a)') -vimrc.map_plug('o', 'i', '(textobj-wiw-i)') -vimrc.map_plug('x', 'i', '(textobj-wiw-i)') +vim.keymap.set('o', 'a', '(textobj-wiw-a)') +vim.keymap.set('x', 'a', '(textobj-wiw-a)') +vim.keymap.set('o', 'i', '(textobj-wiw-i)') +vim.keymap.set('x', 'i', '(textobj-wiw-i)') @@ -1897,9 +1880,9 @@ require('nvim-treesitter.configs').setup { -- window-adjuster {{{2 -vimrc.map('n', 'tRw', ':AdjustScreenWidth', { silent = true }) -vimrc.map('n', 'tRh', ':AdjustScreenHeight', { silent = true }) -vimrc.map('n', 'tRr', ':AdjustScreenWidth AdjustScreenHeight', { silent = true }) +vim.keymap.set('n', 'tRw', 'AdjustScreenWidth') +vim.keymap.set('n', 'tRh', 'AdjustScreenHeight') +vim.keymap.set('n', 'tRr', ':AdjustScreenWidth AdjustScreenHeight', { silent=true }) diff --git a/.config/nvim/lua/vimrc.lua b/.config/nvim/lua/vimrc.lua index 7de36d5..bdf1b38 100644 --- a/.config/nvim/lua/vimrc.lua +++ b/.config/nvim/lua/vimrc.lua @@ -90,78 +90,9 @@ function M.hi_link(from, to) vim.cmd(('highlight! link %s %s'):format(from, to)) end -function M.map(mode, lhs, rhs, opts) - if opts == nil then - opts = {} - end - opts.noremap = true - vim.api.nvim_set_keymap( - mode, - lhs, - rhs, - opts) -end - - -function M.remap(mode, lhs, rhs, opts) - if opts == nil then - opts = {} - end - vim.api.nvim_set_keymap( - mode, - lhs, - rhs, - opts) -end - M.map_callbacks = {} -local map_callback_id = 1 - -function M.map_expr(mode, lhs, rhs, opts) - if opts == nil then - opts = {} - end - opts.noremap = true - opts.expr = true - M.map_callbacks['_' .. map_callback_id] = rhs - vim.api.nvim_set_keymap( - mode, - lhs, - ('v:lua.vimrc.map_callbacks._%d()'):format(map_callback_id), - opts) - map_callback_id = map_callback_id + 1 -end - - -function M.map_cmd(mode, lhs, rhs, opts) - if opts == nil then - opts = {} - end - opts.noremap = true - opts.silent = true - vim.api.nvim_set_keymap( - mode, - lhs, - (':%s'):format(rhs), - opts) -end - - -function M.map_plug(mode, lhs, rhs, opts) - if opts == nil then - opts = {} - end - opts.silent = true - vim.api.nvim_set_keymap( - mode, - lhs, - '' .. rhs, - opts) -end - -M.unmap = vim.api.nvim_del_keymap -- Wrapper of |getchar()|. -- cgit v1.2.3-70-g09d2