From 213651779344f25a8fcce21784e4fbde24117d22 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 9 May 2022 23:08:37 +0900 Subject: neovim: replace :command with Lua API --- .config/nvim/init.lua | 70 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to '.config/nvim/init.lua') diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 056dd5e..8ffe9bd 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -644,12 +644,15 @@ function vimrc.fn.smart_open(command) end end - -vim.cmd([[ -command! -nargs=+ -complete=command - \ SmartOpen - \ call v:lua.vimrc.fn.smart_open() -]]) +vim.api.nvim_create_user_command( + 'SmartOpen', + function(opts) vimrc.fn.smart_open(opts.args) end, + { + desc = 'Smartly open a new buffer', + nargs = '+', + complete = 'command', + } +) @@ -733,11 +736,13 @@ function vimrc.fn.open_scratch() end end -vim.cmd([[ -command! - \ Scratch - \ call v:lua.vimrc.fn.open_scratch() -]]) +vim.api.nvim_create_user_command( + 'Scratch', + function() vimrc.fn.open_scratch() end, + { + desc = 'Open a *scratch* buffer', + } +) vimrc.map('n', 's', 'Scratch', { silent = true }) @@ -844,11 +849,15 @@ vimrc.map('x', 's', '') -- Note: directly calling `g/^/m` will overwrite the current search pattern with -- '^' and highlight it, which is not expected. -- :h :keeppatterns -vim.cmd([[ -command! -bar -range=% - \ Reverse - \ keeppatterns ,g/^/m-1 -]]) +vim.api.nvim_create_user_command( + 'Reverse', + 'keeppatterns ,g/^/m-1', + { + desc = 'Reverse lines', + bar = true, + range = '%', + } +) @@ -870,11 +879,15 @@ end -- If the current buffer is empty, open a file with the current window; -- otherwise open a new tab. -vim.cmd([[ -command! -bar -complete=file -nargs=* - \ SmartTabEdit - \ call v:lua.vimrc.fn.smart_tabedit(, ) -]]) +vim.api.nvim_create_user_command( + 'SmartTabEdit', + function(opts) vimrc.fn.smart_tabedit(opts.mods, opts.args) end, + { + desc = 'Smartly open a file', + nargs = '*', + complete = 'file', + } +) @@ -1687,11 +1700,16 @@ nnoremap (my-insert-blank-lines-before) G.rg_window_location = 'silent! echo' G.rg_jump_to_first = true -vim.cmd([[ -command! -bang -nargs=* -complete=file -bar - \ RG - \ Rg -]]) +vim.api.nvim_create_user_command( + 'RG', + 'Rg ', + { + bang = true, + bar = true, + nargs = '*', + complete = 'file', + } +) -- rust {{{2 -- cgit v1.2.3-70-g09d2