aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/lua/init/02-commands.lua
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-12-21 20:50:12 +0900
committernsfisis <nsfisis@gmail.com>2022-12-21 20:50:12 +0900
commit215f6e0a1cd55b18c20a51fc4f19144326ce3302 (patch)
tree856f58a8732a581c3185966f4644ce3ea6601fd3 /.config/nvim/lua/init/02-commands.lua
parent5155174cc68b09df85ddeb9ba409646472fca029 (diff)
downloaddotfiles-215f6e0a1cd55b18c20a51fc4f19144326ce3302.tar.gz
dotfiles-215f6e0a1cd55b18c20a51fc4f19144326ce3302.tar.zst
dotfiles-215f6e0a1cd55b18c20a51fc4f19144326ce3302.zip
neovim: refactor
Diffstat (limited to '.config/nvim/lua/init/02-commands.lua')
-rw-r--r--.config/nvim/lua/init/02-commands.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/.config/nvim/lua/init/02-commands.lua b/.config/nvim/lua/init/02-commands.lua
index 6c82442..96c83da 100644
--- a/.config/nvim/lua/init/02-commands.lua
+++ b/.config/nvim/lua/init/02-commands.lua
@@ -1,4 +1,6 @@
local F = vim.fn
+local G = vim.g
+local O = vim.o
local C = vim.api.nvim_create_user_command
@@ -19,6 +21,52 @@ C(
)
+-- :SmartOpen {{{1
+
+C(
+ 'SmartOpen',
+ function(opts)
+ local modifiers
+ if F.winwidth(F.winnr()) < 150 then
+ modifiers = 'topleft'
+ else
+ modifiers = 'vertical botright'
+ end
+
+ vim.cmd(([[
+ try
+ %s %s
+ let g:__ok = v:true
+ catch
+ echohl Error
+ echo v:exception
+ echohl None
+ let g:__ok = v:false
+ endtry
+ ]]):format(modifiers, opts.args))
+ if not G.__ok then
+ return
+ end
+
+ if O.filetype == 'help' then
+ if vim.bo.textwidth > 0 then
+ vim.cmd(('vertical resize %d'):format(vim.bo.textwidth))
+ end
+ -- Move the cursor to the beginning of the line as help tags are often
+ -- right-justfied.
+ F.cursor(
+ 0 --[[ stay in the current line ]],
+ 1 --[[ move to the beginning of the line ]])
+ end
+ end,
+ {
+ desc = 'Smartly open a new buffer',
+ nargs = '+',
+ complete = 'command',
+ }
+)
+
+
-- :SmartTabEdit {{{1
-- If the current buffer is empty, open a file with the current window;