Skip to content

Instantly share code, notes, and snippets.

@KensoDev
Created January 22, 2023 16:08
Show Gist options
  • Save KensoDev/12283a551756893262c2126b5368d310 to your computer and use it in GitHub Desktop.
Save KensoDev/12283a551756893262c2126b5368d310 to your computer and use it in GitHub Desktop.
local M = {}
M.WinMove = function(command_key)
local curwin = vim.api.nvim_get_current_win()
vim.cmd(string.format("wincmd %s", command_key))
if curwin == vim.api.nvim_get_current_win() then
if command_key:match("[jk]") then
vim.cmd("wincmd v")
else
vim.cmd("wincmd s")
end
vim.cmd(string.format("wincmd %s", command_key))
end
end
return M
@KensoDev
Copy link
Author

I call this function like this:

    map("n", "<C-h>", "<cmd>lua require('KensoDev.utils').WinMove('h')<CR>", options)
    map("n", "<C-j>", "<cmd>lua require('KensoDev.utils').WinMove('j')<CR>", options)
    map("n", "<C-k>", "<cmd>lua require('KensoDev.utils').WinMove('k')<CR>", options)
    map("n", "<C-l>", "<cmd>lua require('KensoDev.utils').WinMove('l')<CR>", options)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment