From b67f8c76c20c8cb07b5f0aa52f53aaaf9f9f7576 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 19 Dec 2022 01:39:56 +0900 Subject: neovim: refactor: split init.lua --- .config/nvim/lua/init/02-commands.lua | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .config/nvim/lua/init/02-commands.lua (limited to '.config/nvim/lua/init/02-commands.lua') 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 ,g/^/m-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', + } +) -- cgit v1.2.3-70-g09d2