Skip to content
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

navigating between tmux panes works fine but doesn't work in vim split panes #391

Open
lazylance3 opened this issue May 20, 2024 · 14 comments

Comments

@lazylance3
Copy link

lazylance3 commented May 20, 2024

I'm running Ubuntu 22.04.4 LTS via WSL2 on Windows 11

NVIM v0.9.5
tmux 3.2a

Output for :verbose nmap <C-h>

n  <C-H>       * :<C-U>TmuxNavigateLeft<CR>
        Last set from ~/.local/share/nvim/lazy/vim-tmux-navigator/plugin/tmux_navigator.vim line 19

Output for :TmuxNavigatorProcessList

S bash
S nvim-0.9.5

tmux.conf

   1   │# change prefix from Ctrl-B to Ctrl-A
   2   │ unbind C-b
   3   │ set-option -g  prefix C-a
   4   │ bind-key C-a send-prefix
   5   │
   6   │ # Enable mouse mode
   7   │ set -g mouse on
   8   │
   9   │ # Start counting pane and window number at 1
  10   │ set -g base-index 1
  11   │ setw -g pane-base-index 1
  12   │
  13   │ # Use xclip to copy and paste with the system clipboard
  14   │ bind C-c run "tmux save-buffer - | xclip -i -sel clip"
  15   │ bind C-v run "tmux set-buffer $(xclip -o -sel clip); tmux paste-buffer"
  16   │
  17   │ # remap split pane keybindings
  18   │ bind '|' split-window -h
  19   │ bind '-' split-window -v
  20   │
  21   │ # use different cursors for insert vs normal mode
  22   │ set -ga terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'
  23   │
  24   │ # Smart pane switching with awareness of Vim splits.
  25   │ # See: https://github.com/christoomey/vim-tmux-navigator
  26   │ is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
  27   │     | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
  28   │ bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
  29   │ bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
  30   │ bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
  31   │ bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
  32   │ tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
  33   │ if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
  34   │     "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
  35   │ if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
  36   │     "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"
  37   │
  38   │ bind-key -T copy-mode-vi 'C-h' select-pane -L
  39   │ bind-key -T copy-mode-vi 'C-j' select-pane -D
  40   │ bind-key -T copy-mode-vi 'C-k' select-pane -U
  41   │ bind-key -T copy-mode-vi 'C-l' select-pane -R
  42   │ bind-key -T copy-mode-vi 'C-\' select-pane -l

I'm using lazy.nvim as my nvim plugin manager and this is the only thing I have in plugins/init.lua

   1  │ return {
   2  │   "nvim-lua/plenary.nvim",
   3  │   "christoomey/vim-tmux-navigator",
   4  │   cmd = {
   5  │     "TmuxNavigateLeft",
   6  │     "TmuxNavigateDown",
   7  │     "TmuxNavigateUp",
   8  │     "TmuxNavigateRight",
   9  │     "TmuxNavigatePrevious",
  10  │   },
  11  │   keys = {
  12  │     { "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
  13  │     { "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
  14  │     { "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
  15  │     { "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
  16  │     { "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
  17  │   },
  18  │ }
@lazylance3
Copy link
Author

lazylance3 commented May 20, 2024

I opened vim outside a tmux session and the keybindings <C-h>.. (etc) now work in vim split panes. I'm assuming this is an issue in my .tmux.conf?

@spenrose
Copy link

I am seeing same issue.

@rgeddes
Copy link

rgeddes commented May 20, 2024

Linux Mint 21
nvim 0.10.0

I had a similar issue and found this change to .tmux.conf to be helpful:

--- is_vim="ps -o state= -o comm= -t '#{pane_tty}'
--- | grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"

+++ is_vim="ps -o args -g $$ | grep -iqE 'n?vim?x?'"

I don't know all the ins and outs of ps, but it seems to work for me.

On the other hand, is taken over by tmux and interferes with digraphs in nvim.

@htlin222
Copy link

I am experiencing the same issue. Pane switching in Neovim works fine when I'm not in a tmux session. However, if I map <Ctrl+hjkl> to another command, such as echom 'Hello', nothing happens. It seems that tmux is intercepting the <Ctrl+hjkl> keybindings. @rgeddes's approach seems to be on the right track, but it still doesn't work for me.

@HzTTT
Copy link

HzTTT commented Jun 16, 2024

I encountered the same issue. After installing the Fig plugin, the ttys sequence in my terminal got messed up, causing the #{pane_tty} parameter to be passed incorrectly.

Here is the output of the ps command:

15775 ttys004    0:00.37 zsh (figterm)
15786 ttys005    0:00.33 /bin/zsh --login
15821 ttys005    0:00.01 /bin/zsh --login
15861 ttys005    0:00.00 /bin/zsh --login
15862 ttys005    0:00.00 /bin/zsh --login
15864 ttys005    0:00.01 /Users/chh/.cache/gitstatus/gitstatusd-darwin-arm64 -G v1.5.4 -s -1
15866 ttys005    0:00.09 nvim

The value of #{pane_tty} is ttys004, but nvim is running on ttys005, causing vim's detection to fail.

Solution: Check if the output of #{pane_tty} matches the ttys where nvim is running. If not, it could be due to the influence of terminal plugins. My temporary solution is to uninstall Fig.

@htlin222
Copy link

@HzTTT Suggestion worked. Fig is now changed to Amazon Q for command line. Uninstalling the latter solved the problem. Thank you. 🙏

@HzTTT
Copy link

HzTTT commented Jun 17, 2024

@htlin222 How do you use Amazon Q for command line?😭I seem to still be having issues with it.
Here is my ps output:

PID TTY           TIME CMD
79402 ttys000    0:00.15 zsh (qterm)
79411 ttys002    0:00.08 /bin/zsh --login
79475 ttys002    0:00.00 /bin/zsh --login
79476 ttys002    0:00.02 q _ inline-shell-completion --buffer ps

The first ttys000 zsh (qterm) is mistakenly recognized by #{pane_tty}, but nvim should be on ttys002.

@neurosnap
Copy link

Possibly unrelated, but I run neovim inside alpine and ran into the same issue described above. Not sure if this was a recent change or not but I needed to install procps for things to work properly. Definitely check that ps command.

@HzTTT
Copy link

HzTTT commented Jun 19, 2024

@neurosnap I'm using mac.procps doesn't seem to support mac.

@dbagia
Copy link

dbagia commented Jun 19, 2024

I am using nvim inside an alpine docker container and I have the same issue. What I have observed is that this started happening recently so I guess it was caused by a recent change?

@dehidehidehi
Copy link

I had the same issue and found a solution.

Opening split paned in Vim and a terminal buffer -> no issues moving in and out.
Doing the same but from within Tmux -> I couldn't move into the terminal buffer.

This update changed the mappings from noremap to nnoremap.
c600cf1

Reverting the changes by adding the following config to my vimrc fixed my issue:

let g:tmux_navigator_no_mappings = 0
noremap <silent> <C-h> :<C-U>TmuxNavigateLeft<cr>
noremap <silent> <C-j> :<C-U>TmuxNavigateDown<cr>
noremap <silent> <C-k> :<C-U>TmuxNavigateUp<cr>
noremap <silent> <C-l> :<C-U>TmuxNavigateRight<cr>
noremap <silent> <C-\> :<C-U>TmuxNavigatePrevious<cr>

@JuiceDrinker
Copy link

JuiceDrinker commented Jul 19, 2024

Any update on this issue? Facing the same problem where vim pane navigation works great outside of tmux, tmux <-> vim navigation works great in tmux but cannot change vim panes inside tmux. Tried both above fixes but to no avail. Thanks for your help!

@Edgar-P-yan
Copy link

Had the same problem, uninstalling Amazon Q (prior Fig) fixes the issue. But if you want both Amazon Q and vim-tmux-navigator to work you have to modify the is_vim expression of the plugin. Check out the Fig's Known Issues page https://github.com/withfig/fig/blob/main/KNOWN-ISSUES.md#vim-tmux-navigator and this comment here #295 (comment)

@paolomissagia
Copy link

paolomissagia commented Oct 7, 2024

Possibly unrelated, but I run neovim inside alpine and ran into the same issue described above. Not sure if this was a recent change or not but I needed to install procps for things to work properly. Definitely check that ps command.

That was the issue here, thanks @dbagia.

PS: I am running a Fedora 40 rootfs inside of WSL2 - that does not happen on Fedora 40 Workstation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests