-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bindings only work between tmux and nvim #28
Comments
Hello, Yes, that should be the case by default! This means you probably didn't configure the plugin correctly, so make sure that is first properly configured, before continuing debugging. I might be able to help if you reproduce a minimal working environment and paste the configuration here. Best |
Thanks @alexghergh . lazy spec for plugin: { 'alexghergh/nvim-tmux-navigation', config = function()
local nvim_tmux_nav = require('nvim-tmux-navigation')
nvim_tmux_nav.setup {
disable_when_zoomed = true -- defaults to false
}
vim.keymap.set('n', "<C-h>", nvim_tmux_nav.NvimTmuxNavigateLeft)
vim.keymap.set('n', "<C-j>", nvim_tmux_nav.NvimTmuxNavigateDown)
vim.keymap.set('n', "<C-k>", nvim_tmux_nav.NvimTmuxNavigateUp)
vim.keymap.set('n', "<C-l>", nvim_tmux_nav.NvimTmuxNavigateRight)
vim.keymap.set('n', "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive)
vim.keymap.set('n', "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext)
end
} relevant tmux:
|
Hmm, I'm not too sure about lazy, but I think you have to specify { 'alexghergh/nvim-tmux-navigation', lazy = false, config = function()
local nvim_tmux_nav = require('nvim-tmux-navigation')
nvim_tmux_nav.setup {
disable_when_zoomed = true -- defaults to false
}
vim.keymap.set('n', "<C-h>", nvim_tmux_nav.NvimTmuxNavigateLeft)
vim.keymap.set('n', "<C-j>", nvim_tmux_nav.NvimTmuxNavigateDown)
vim.keymap.set('n', "<C-k>", nvim_tmux_nav.NvimTmuxNavigateUp)
vim.keymap.set('n', "<C-l>", nvim_tmux_nav.NvimTmuxNavigateRight)
vim.keymap.set('n', "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive)
vim.keymap.set('n', "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext)
end
} You can even go as far as: {
'alexghergh/nvim-tmux-navigation',
opts = {
disable_when_zoomed = true,
keybindings = {
left = '<C-h>',
down = '<C-j>',
up = '<C-k>',
right = '<C-l>',
last_active = '<C-\\>',
next = '<C-Space>',
},
},
lazy = false,
}, or something like this. Let me know if it works for you! |
I tried both approaches neither changed the behavior. I don't think it is a problem loading the plugin as it does work, it just doesn't work on the vim splits, but it does happily change to the tmux and back again. |
Also, it does not work on vim splits if I only have one tmux split with nvim running in it, if that makes this any clearer. |
I have been looking at this a bit more and it looks like this is an issue with the tmux side. The command to check if it is in vim ( returns Thanks for your help in this. Hopefully I will find a fix for this. |
Found current issue in "christoomey/vim-tmux-navigator` |
It seems that changing the For anyone else facing this issue, see christoomey/vim-tmux-navigator#295 (comment) |
So the issue seems solved, at least on our side, right? Great! |
It is solved, but other users of your awesome plugin will most likely experience this issue if they follow the instructions on the README. Would you consider adding a comment about the tmux flag if nvim is running in a subshell or accept a PR doing so? |
I don't think the examples work with lazyvim (anymore?)? For anyone else running in to keymaps not registering, this might point you in the right direction:https://www.reddit.com/r/neovim/comments/14yer8w/neovimtmux_navigation_plugin_with_lazyvim_not/ For me, the LazyVim keymappings overwrote the Navigator ones. Kinda hard to spot since it worked from tmux in to NeoVim then inside NeoVim but not back out again. Solved the keybindings by also adding this to my
|
There seems to be a rather elegant solution suggested in christoomey/vim-tmux-navigator/issues/295#issuecomment-1123455337 Porting the following to lua could alleviate the dependency on the tmux-side plugin altogether, only requiring the short Tmux snippet attached under. function! s:set_is_vim()
call s:TmuxCommand("set-option -p @is_vim yes")
endfunction
function! s:unset_is_vim()
call s:TmuxCommand("set-option -p -u @is_vim")
endfunction
augroup tmux_navigator_is_vim
au!
autocmd VimEnter * call s:set_is_vim()
autocmd VimLeave * call s:unset_is_vim()
if exists('##VimSuspend')
autocmd VimSuspend * call s:unset_is_vim()
autocmd VimResume * call s:set_is_vim()
endif
augroup END Tmux snippet: bind -n C-h if-shell -F "#{@is_vim}" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell -F "#{@is_vim}" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell -F "#{@is_vim}" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell -F "#{@is_vim}" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell -F "#{@is_vim}" "send-keys C-\\" "select-pane -l" @alexghergh would you consider such a change? |
Following up on my suggestion above, currently this lazy.nvim setup works for me: Plugin: return {
"alexghergh/nvim-tmux-navigation",
config = function()
require("nvim-tmux-navigation").setup({
disable_when_zoomed = true, -- defaults to false
keybindings = {
left = "<C-h>",
down = "<C-j>",
up = "<C-k>",
right = "<C-l>",
last_active = "<C-\\>",
next = "<C-Space>",
},
})
local function tmux_command(command)
local tmux_socket = vim.fn.split(vim.env.TMUX, ",")[1]
return vim.fn.system("tmux -S " .. tmux_socket .. " " .. command)
end
local nvim_tmux_nav_group = vim.api.nvim_create_augroup("NvimTmuxNavigation", {})
vim.api.nvim_create_autocmd({ "VimEnter", "VimResume" }, {
group = nvim_tmux_nav_group,
callback = function()
tmux_command("set-option -p @is_vim yes")
end,
})
vim.api.nvim_create_autocmd({ "VimLeave", "VimSuspend" }, {
group = nvim_tmux_nav_group,
callback = function()
tmux_command("set-option -p -u @is_vim")
end,
})
end,
}
bind -n C-h if-shell -F "#{@is_vim}" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell -F "#{@is_vim}" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell -F "#{@is_vim}" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell -F "#{@is_vim}" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell -F "#{@is_vim}" "send-keys C-\\" "select-pane -l" |
For whoever ends up here, to get this working with LazyVim, I combined |
Is it possible to have this navigate all splits and not just between nvim and tmux?
Take the following: There are three panes, 2 are nvim windows in a tmux split and the right most is the 2nd tmux split.
If I navigate using any on the NvimTmuxNaviate[xxx] commands they only switch from nvim to tmux and vice-versa. It would be nice if I could start on the left pane and navigate across it in order (or the reverse) going from nvim window to nvim window, then tmux split.
This would ease the workflow as one keybinding would work across all splits and I wouldn't have to switch to
C-w
commands for vim windows.The text was updated successfully, but these errors were encountered: