Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Pander
a6b3250434 Consolidate tmux and vim navigation 2026-02-15 20:23:16 +01:00
Martin Pander
4049d3981b Consolidate tmux window and pane switching 2026-02-15 20:18:30 +01:00
4 changed files with 59 additions and 16 deletions

24
flake.lock generated
View File

@@ -101,11 +101,11 @@
]
},
"locked": {
"lastModified": 1770184146,
"narHash": "sha256-DsqnN6LvXmohTRaal7tVZO/AKBuZ02kPBiZKSU4qa/k=",
"lastModified": 1770922915,
"narHash": "sha256-6J/JoK9iL7sHvKJcGW2KId2agaKv1OGypsa7kN+ZBD4=",
"owner": "LnL7",
"repo": "nix-darwin",
"rev": "0d7874ef7e3ba02d58bebb871e6e29da36fa1b37",
"rev": "6c5a56295d2a24e43bcd8af838def1b9a95746b2",
"type": "github"
},
"original": {
@@ -159,11 +159,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1770562336,
"narHash": "sha256-ub1gpAONMFsT/GU2hV6ZWJjur8rJ6kKxdm9IlCT0j84=",
"lastModified": 1771008912,
"narHash": "sha256-gf2AmWVTs8lEq7z/3ZAsgnZDhWIckkb+ZnAo5RzSxJg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d6c71932130818840fc8fe9509cf50be8c64634f",
"rev": "a82ccc39b39b621151d6732718e3e250109076fa",
"type": "github"
},
"original": {
@@ -175,11 +175,11 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1770617025,
"narHash": "sha256-1jZvgZoAagZZB6NwGRv2T2ezPy+X6EFDsJm+YSlsvEs=",
"lastModified": 1771043024,
"narHash": "sha256-O1XDr7EWbRp+kHrNNgLWgIrB0/US5wvw9K6RERWAj6I=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2db38e08fdadcc0ce3232f7279bab59a15b94482",
"rev": "3aadb7ca9eac2891d52a9dec199d9580a6e2bf44",
"type": "github"
},
"original": {
@@ -241,11 +241,11 @@
]
},
"locked": {
"lastModified": 1770683991,
"narHash": "sha256-xVfPvXDf9QN3Eh9dV+Lw6IkWG42KSuQ1u2260HKvpnc=",
"lastModified": 1771166946,
"narHash": "sha256-UFc4lfGBr+wJmwgDGJDn1cVD6DTr0/8TdronNUiyXlU=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "8b89f44c2cc4581e402111d928869fe7ba9f7033",
"rev": "2d0cf89b4404529778bc82de7e42b5754e0fe4fa",
"type": "github"
},
"original": {

View File

@@ -60,6 +60,7 @@ in
copilot-cmp
CopilotChat-nvim
opencode-nvim
vim-tmux-navigator
bullets-vim
nvim-dap
nvim-nio

View File

@@ -23,11 +23,15 @@ in
unbind S
bind S command-prompt "switch -t %1"
bind-key -n M-K switch-client -p
bind-key -n M-J switch-client -n
# Check if we are in vim
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n M-L next-window
bind-key -n M-H previous-window
bind-key -n M-K if-shell "$is_vim" "send-keys M-K" "if -F \"#{pane_at_top}\" \"switch-client -p\" \"select-pane -U\""
bind-key -n M-J if-shell "$is_vim" "send-keys M-J" "if -F \"#{pane_at_bottom}\" \"switch-client -n\" \"select-pane -D\""
bind-key -n M-L if-shell "$is_vim" "send-keys M-L" "if -F \"#{pane_at_right}\" \"next-window\" \"select-pane -R\""
bind-key -n M-H if-shell "$is_vim" "send-keys M-H" "if -F \"#{pane_at_left}\" \"previous-window\" \"select-pane -L\""
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"

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)