Consolidate tmux and vim navigation

This commit is contained in:
Martin Pander
2026-02-15 20:23:16 +01:00
parent 4049d3981b
commit a6b3250434
3 changed files with 47 additions and 4 deletions

View File

@@ -129,3 +129,41 @@ vim.keymap.set('n', "<F11>", function() require("dap").step_into() end)
vim.keymap.set('n', "<F10>", function() require("dap").step_over() end)
vim.keymap.set('n', "<F12>", function() require("dap").step_out() end)
-- Tmux Navigator
vim.g.tmux_navigator_no_mappings = 1
local function tmux_navigate(direction)
local old_win = vim.api.nvim_get_current_win()
vim.cmd('wincmd ' .. direction)
local new_win = vim.api.nvim_get_current_win()
if old_win == new_win then
-- We are at the edge, let tmux handle it
-- This requires the tmux config to be set up to handle these keys when not in vim,
-- BUT since we are IN vim, we need to explicitly trigger the tmux action.
-- However, simply sending the key to tmux might just send it back to vim if we aren't careful,
-- or we can just run the tmux command directly.
local tmux_cmd = ""
if direction == 'h' then
tmux_cmd = 'if -F "#{pane_at_left}" "previous-window" "select-pane -L"'
elseif direction == 'j' then
tmux_cmd = 'if -F "#{pane_at_bottom}" "switch-client -n" "select-pane -D"'
elseif direction == 'k' then
tmux_cmd = 'if -F "#{pane_at_top}" "switch-client -p" "select-pane -U"'
elseif direction == 'l' then
tmux_cmd = 'if -F "#{pane_at_right}" "next-window" "select-pane -R"'
end
-- We use vim.fn.system to execute the tmux command
-- We need to wrap the command in 'tmux' call
vim.fn.system('tmux ' .. tmux_cmd)
end
end
vim.keymap.set('n', '<M-H>', function() tmux_navigate('h') end)
vim.keymap.set('n', '<M-J>', function() tmux_navigate('j') end)
vim.keymap.set('n', '<M-K>', function() tmux_navigate('k') end)
vim.keymap.set('n', '<M-L>', function() tmux_navigate('l') end)