diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-12-19 01:39:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-12-19 02:02:41 +0900 |
| commit | b67f8c76c20c8cb07b5f0aa52f53aaaf9f9f7576 (patch) | |
| tree | eb6e8f3786e791ffd71a33f4ee75079470dc9630 /.config/nvim/lua/init/02-commands.lua | |
| parent | ae9846c9563f398b51927d499f0bfe45c9f53185 (diff) | |
| download | dotfiles-b67f8c76c20c8cb07b5f0aa52f53aaaf9f9f7576.tar.gz dotfiles-b67f8c76c20c8cb07b5f0aa52f53aaaf9f9f7576.tar.zst dotfiles-b67f8c76c20c8cb07b5f0aa52f53aaaf9f9f7576.zip | |
neovim: refactor: split init.lua
Diffstat (limited to '.config/nvim/lua/init/02-commands.lua')
| -rw-r--r-- | .config/nvim/lua/init/02-commands.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/.config/nvim/lua/init/02-commands.lua b/.config/nvim/lua/init/02-commands.lua new file mode 100644 index 0000000..541e8da --- /dev/null +++ b/.config/nvim/lua/init/02-commands.lua @@ -0,0 +1,47 @@ +local F = vim.fn +local C = vim.api.nvim_create_user_command + + +-- :Reverse {{{1 + +-- Reverse a selected range in line-wise. +-- Note: directly calling `g/^/m` will overwrite the current search pattern with +-- '^' and highlight it, which is not expected. +-- :h :keeppatterns +C( + 'Reverse', + 'keeppatterns <line1>,<line2>g/^/m<line1>-1', + { + desc = 'Reverse lines', + bar = true, + range = '%', + } +) + + +-- :SmartTabEdit {{{1 + +-- If the current buffer is empty, open a file with the current window; +-- otherwise open a new tab. +C( + 'SmartTabEdit', + function(opts) + local is_empty_buffer = ( + F.bufname() == '' + and not vim.bo.modified + and F.line('$') <= 1 + and F.getline('.') == '' + ) + + if is_empty_buffer then + vim.cmd(mods .. ' edit ' .. args) + else + vim.cmd(mods .. ' tabedit ' .. args) + end + end, + { + desc = 'Smartly open a file', + nargs = '*', + complete = 'file', + } +) |
