summaryrefslogtreecommitdiff
path: root/.config/nvim
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-08-17 23:49:19 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-08-17 23:49:19 +0200
commita43c8b2d1e426893e9a61a3e71315e8caeeb6ee2 (patch)
tree1553715250cf760c27bd976fc7051af6e5bbd2a8 /.config/nvim
parent8f6ffa5087ab476e3af4153150fa3a588d9ea53f (diff)
nvim: Create winmove for faster window/tab movement
Diffstat (limited to '.config/nvim')
-rw-r--r--.config/nvim/init.lua8
-rw-r--r--.config/nvim/plugin/winmove.vim47
2 files changed, 51 insertions, 4 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
index c44aa7f..285b334 100644
--- a/.config/nvim/init.lua
+++ b/.config/nvim/init.lua
@@ -56,14 +56,14 @@ vim.keymap.set('x', '<Leader>a', 'gg0oG$',
{ desc = 'Select the [A]ll of the buffer' })
vim.keymap.set('o', '<Leader>a', ':normal! ggVG<CR>',
{ desc = 'Text object of [A]ll of the buffer', silent = true })
-vim.keymap.set('n', '<C-h>', '<C-w><C-h>',
- { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>',
{ desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>',
{ desc = 'Move focus to the upper window' })
-vim.keymap.set('n', '<C-l>', '<C-w><C-l>',
- { desc = 'Move focus to the right window' })
+vim.keymap.set('n', '<C-h>', ':WinMovePrev<CR>',
+ { desc = 'Move focus to the left window', silent = true })
+vim.keymap.set('n', '<C-l>', ':WinMoveNext<CR>',
+ { desc = 'Move focus to the right window', silent = true })
vim.keymap.set('n', '<Leader>h', function() vim.cmd 'split' end,
{ desc = 'Open a [H]orizontal split' })
vim.keymap.set('n', '<Leader>v', function() vim.cmd 'vsplit' end,
diff --git a/.config/nvim/plugin/winmove.vim b/.config/nvim/plugin/winmove.vim
new file mode 100644
index 0000000..a72f6ab
--- /dev/null
+++ b/.config/nvim/plugin/winmove.vim
@@ -0,0 +1,47 @@
+if &cp || exists('g:loaded_winmove')
+ finish
+endif
+let g:loaded_winmove = v:true
+
+function! winmove#Next()
+ let l:n1 = winnr()
+ wincmd l
+ if l:n1 != winnr()
+ return
+ endif
+
+ tabnext
+
+ let l:n1 = winnr()
+ while v:true
+ wincmd h
+ let l:n2 = winnr()
+ if l:n1 == l:n2
+ return
+ endif
+ let l:n1 = l:n2
+ endwhile
+endfunction
+
+function! winmove#Prev()
+ let l:n1 = winnr()
+ wincmd h
+ if l:n1 != winnr()
+ return
+ endif
+
+ tabprev
+
+ let l:n1 = winnr()
+ while v:true
+ wincmd l
+ let l:n2 = winnr()
+ if l:n1 == l:n2
+ return
+ endif
+ let l:n1 = l:n2
+ endwhile
+endfunction
+
+command! -nargs=0 WinMoveNext call winmove#Next()
+command! -nargs=0 WinMovePrev call winmove#Prev()