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/colors/ocean.lua | 7 ---- .config/nvim/init.lua | 70 +++++++++++++++++++++++++--------------- .config/nvim/plugin/autosave.lua | 30 +++++++++++++++++ .config/nvim/plugin/autosave.vim | 21 ------------ .config/nvim/plugin/leaf.vim | 8 ----- TODO | 2 -- 6 files changed, 74 insertions(+), 64 deletions(-) create mode 100644 .config/nvim/plugin/autosave.lua delete mode 100644 .config/nvim/plugin/autosave.vim diff --git a/.config/nvim/colors/ocean.lua b/.config/nvim/colors/ocean.lua index 289b075..342f26e 100644 --- a/.config/nvim/colors/ocean.lua +++ b/.config/nvim/colors/ocean.lua @@ -278,10 +278,3 @@ link('sqlKeyword', 'SyntaxStatement2') --- Utilities {{{1 - -vim.cmd([[ -command! -bar - \ OceanGetHighlightGroupName - \ echo synIDattr(synID(line('.'), col('.'), v:false), 'name') -]]) 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 diff --git a/.config/nvim/plugin/autosave.lua b/.config/nvim/plugin/autosave.lua new file mode 100644 index 0000000..6725195 --- /dev/null +++ b/.config/nvim/plugin/autosave.lua @@ -0,0 +1,30 @@ +if vim.g.loaded_autosave then + return +end + +vim.api.nvim_create_user_command( + 'AutosaveEnable', + function() require('autosave').enable() end, + { + desc = '[Autosave] enable autosaving', + bar = true, + } +) +vim.api.nvim_create_user_command( + 'AutosaveDisable', + function() require('autosave').disable() end, + { + desc = '[Autosave] disable autosaving', + bar = true, + } +) +vim.api.nvim_create_user_command( + 'AutosaveToggle', + function() require('autosave').toggle() end, + { + desc = '[Autosave] toggle autosaving', + bar = true, + } +) + +vim.g.loaded_autosave = true diff --git a/.config/nvim/plugin/autosave.vim b/.config/nvim/plugin/autosave.vim deleted file mode 100644 index ab8a227..0000000 --- a/.config/nvim/plugin/autosave.vim +++ /dev/null @@ -1,21 +0,0 @@ -scriptencoding utf-8 - -if exists('g:loaded_autosave') - finish -endif - - -command! -bar - \ AutosaveEnable - \ lua require('autosave').enable() - -command! -bar - \ AutosaveDisable - \ lua require('autosave').disable() - -command! -bar - \ AutosaveToggle - \ lua require('autosave').toggle() - - -let g:loaded_autosave = 1 diff --git a/.config/nvim/plugin/leaf.vim b/.config/nvim/plugin/leaf.vim index 5d0d580..bc19053 100644 --- a/.config/nvim/plugin/leaf.vim +++ b/.config/nvim/plugin/leaf.vim @@ -9,14 +9,6 @@ nmap nmap l (leaf) nnoremap (leaf) -nnoremap (leaf)i SmartTabEdit ~/leaves/INBOX.leaf -nnoremap (leaf)t SmartTabEdit ~/leaves/TODO.leaf -nnoremap (leaf)c SmartTabEdit ~/leaves/CALENDAR.leaf -nnoremap (leaf)p SmartTabEdit ~/leaves/PROJECTS.leaf -nnoremap (leaf)s SmartTabEdit ~/leaves/SOMEDAY.leaf -nnoremap (leaf)r SmartTabEdit ~/leaves/REFS.leaf -nnoremap (leaf)A SmartTabEdit ~/leaves/ARCHIVES.leaf - nnoremap (leaf)l SmartTabEdit ~/leaves/INBOX.leaf normal G diff --git a/TODO b/TODO index 098b619..3251314 100644 --- a/TODO +++ b/TODO @@ -2,8 +2,6 @@ nvim 0.7 https://github.com/neovim/neovim/releases/tag/v0.7.0 keymap - highlight - nvim_{add,del}_user_command newsboat Share "urls" file between machines without opening the content -- cgit v1.2.3-70-g09d2