aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/init.lua
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-05-09 23:08:37 +0900
committernsfisis <nsfisis@gmail.com>2022-05-09 23:08:37 +0900
commit213651779344f25a8fcce21784e4fbde24117d22 (patch)
tree72c7870da2237d1e44a906b766d89d4108e5eaae /.config/nvim/init.lua
parentd7f54d84afae5347f4cf1cffa63122ffad1dc1c0 (diff)
downloaddotfiles-213651779344f25a8fcce21784e4fbde24117d22.tar.gz
dotfiles-213651779344f25a8fcce21784e4fbde24117d22.tar.zst
dotfiles-213651779344f25a8fcce21784e4fbde24117d22.zip
neovim: replace :command with Lua API
Diffstat (limited to '.config/nvim/init.lua')
-rw-r--r--.config/nvim/init.lua70
1 files changed, 44 insertions, 26 deletions
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(<q-args>)
-]])
+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', '<Space>s', '<Cmd>Scratch<CR>', { silent = true })
@@ -844,11 +849,15 @@ vimrc.map('x', 's', '<Nop>')
-- 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 <line1>,<line2>g/^/m<line1>-1
-]])
+vim.api.nvim_create_user_command(
+ 'Reverse',
+ 'keeppatterns <line1>,<line2>g/^/m<line1>-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(<q-mods>, <q-args>)
-]])
+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 <silent> <Plug>(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<bang> <args>
-]])
+vim.api.nvim_create_user_command(
+ 'RG',
+ 'Rg<bang> <args>',
+ {
+ bang = true,
+ bar = true,
+ nargs = '*',
+ complete = 'file',
+ }
+)
-- rust {{{2