diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-01-31 22:02:08 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-01-31 22:02:08 +0900 |
| commit | 9f85b2508209de9df73a223768ee0162fb87c1d0 (patch) | |
| tree | 33f7b42d3b2dc7bf685d8e9fbc3cfff571a77b65 | |
| parent | 7418fc3d5a0846b7ce45c342288c6d157b7bebba (diff) | |
| download | dotfiles-9f85b2508209de9df73a223768ee0162fb87c1d0.tar.gz dotfiles-9f85b2508209de9df73a223768ee0162fb87c1d0.tar.zst dotfiles-9f85b2508209de9df73a223768ee0162fb87c1d0.zip | |
neovim: add SmartTabEdit command
| -rw-r--r-- | .config/nvim/init.lua | 28 | ||||
| -rw-r--r-- | .config/nvim/plugin/leaf.vim | 16 |
2 files changed, 35 insertions, 9 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 52b814c..830310f 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -733,7 +733,7 @@ function vimrc.fn.open_scratch() if F.isdirectory(dir) == 0 then F.mkdir(dir, 'p') end - vim.cmd(('edit %s/%s.%s'):format(dir, fname, ext)) + vim.cmd(('SmartTabEdit %s/%s.%s'):format(dir, fname, ext)) if vim.bo.filetype ~= ft then vim.cmd('setlocal filetype=' .. ft) end @@ -856,6 +856,32 @@ command! -bar -range=% +function vimrc.fn.smart_tabedit(mods, args) + 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 + + +-- 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>) +]]) + + + -- Appearance {{{1 -- Color scheme {{{2 diff --git a/.config/nvim/plugin/leaf.vim b/.config/nvim/plugin/leaf.vim index e4826b3..5d0d580 100644 --- a/.config/nvim/plugin/leaf.vim +++ b/.config/nvim/plugin/leaf.vim @@ -9,15 +9,15 @@ nmap <Space> <Nop> nmap <Space>l (leaf) nnoremap (leaf) <Nop> -nnoremap (leaf)i <Cmd>tabedit ~/leaves/INBOX.leaf<CR> -nnoremap (leaf)t <Cmd>tabedit ~/leaves/TODO.leaf<CR> -nnoremap (leaf)c <Cmd>tabedit ~/leaves/CALENDAR.leaf<CR> -nnoremap (leaf)p <Cmd>tabedit ~/leaves/PROJECTS.leaf<CR> -nnoremap (leaf)s <Cmd>tabedit ~/leaves/SOMEDAY.leaf<CR> -nnoremap (leaf)r <Cmd>tabedit ~/leaves/REFS.leaf<CR> -nnoremap (leaf)A <Cmd>tabedit ~/leaves/ARCHIVES.leaf<CR> +nnoremap (leaf)i <Cmd>SmartTabEdit ~/leaves/INBOX.leaf<CR> +nnoremap (leaf)t <Cmd>SmartTabEdit ~/leaves/TODO.leaf<CR> +nnoremap (leaf)c <Cmd>SmartTabEdit ~/leaves/CALENDAR.leaf<CR> +nnoremap (leaf)p <Cmd>SmartTabEdit ~/leaves/PROJECTS.leaf<CR> +nnoremap (leaf)s <Cmd>SmartTabEdit ~/leaves/SOMEDAY.leaf<CR> +nnoremap (leaf)r <Cmd>SmartTabEdit ~/leaves/REFS.leaf<CR> +nnoremap (leaf)A <Cmd>SmartTabEdit ~/leaves/ARCHIVES.leaf<CR> -nnoremap (leaf)l <Cmd>tabedit ~/leaves/INBOX.leaf <Bar>normal G<CR> +nnoremap (leaf)l <Cmd>SmartTabEdit ~/leaves/INBOX.leaf <Bar>normal G<CR> let g:loaded_leaf = 1 |
