christoomey / vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
MIT License
5.23k stars 323 forks source link

Movement within vim splits does not work on remote #238

Open jessebett opened 5 years ago

jessebett commented 5 years ago

I am having issues with the tmux side of this. I have tried both recommended installation methods with no success.

My particular problem is that I am unable to navigate between vim splits using the ctrl-hjkl movement. This does work locally, I am able to navigate vim panes. However, when I ssh into a remote machine, and open tmux -> nvim -> :split I am unable to navigate those splits with ctrl-jk.

This is definitely an issue on the tmux side of things, as within vim I am able to run :TmuxNavigateRight and it works. To clarify, I am able to move from the vim pane to the tmux panes, but not between the vim splits.

I would love some help to debug this. I've tried removing everything in my tmux config except for the tpm plugin with the vim-tmux-navigator line with no success.

I've also tried running the commands that the manual mode relies on

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

I get error: TTY not found so any guidance on how to debug would be helpful. Thanks.

and get weird errors.

christoomey commented 5 years ago

Hello @jamesoff, are you running the is_vim command from within tmux? There is a placeholder of #{pane_tty} that tmux will interpolate before running the command, but if you're running that from the shell it will fail. Just to double check, you can run tmux display -t 0 -p '#{pane_tty}' | xargs ps -o state= -o comm= -t (change the 0 to whatever the index of the vim pane is) and grab the output of that. It should look something like:

S+   /usr/bin/vim
Ss   zsh

Also, just to double check the configuration, can you share the output of tmux list-keys -T root | grep 'C-[hjkl]'?

jessebett commented 5 years ago

Also hello to @jamesoff :p

So I do not actually know how to run the is_vim command from within tmux.

I have

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

inside my .tmux.conf. But if I prefix-: is_vim I get Unknown command is_vim

If you mean by "within tmux" you only mean that I'm already inside a tmux session, then yes I am running it that way. The command that you suggested does work, however:

❯ tmux display -t 0 -p '#{pane_tty}' | xargs ps -o state= -o comm= -t
S zsh
S zsh
S gitstatusd-linu
─────────────────────────────────────────────────────
~                               0.05s jessebett@vws13
❯ tmux display -t 1 -p '#{pane_tty}' | xargs ps -o state= -o comm= -t
S zsh
S zsh
S gitstatusd-linu
S AppRun

(note that I had setw -g pane-base-index 1 previously, so I printed both 0 and 1 panes.

I do not see nvim listed there, only zsh Though, when I am in the nvim pane the bottom tmux window title becomes nvim, so tmux is somehow aware that is my selected pane.

I've taken a screenshot of this below.

Screen Shot 2019-07-26 at 4 11 34 PM

Here is the output of the list-keys command:

bind-key -T root C-h              if-shell "ps -o state= -o comm= -t '#{pane_tty}'     | grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'" "send-keys C-h" "select-pane -L"
bind-key -T root C-j              if-shell "ps -o state= -o comm= -t '#{pane_tty}'     | grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'" "send-keys C-j" "select-pane -D"
bind-key -T root C-k              if-shell "ps -o state= -o comm= -t '#{pane_tty}'     | grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'" "send-keys C-k" "select-pane -U"
bind-key -T root C-l              if-shell "ps -o state= -o comm= -t '#{pane_tty}'     | grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'" "send-keys C-l" "select-pane -R"
miker985 commented 5 years ago

I also experience this issue, but I assumed it was because is_vim is somewhat limited.

$ tmux display -t 6 -p '#{pane_tty}' | xargs ps -o state= -o comm= -t
S ssh
S bash

In my case everything is working, except is_vim has no way of telling if the ssh session is a vim command or something else. The result is that for remote editing (ssh -> vim -> vim splits) I need to use inbuilt vim commands.

sdondley commented 3 years ago

It's because the $TMUX environment variable on a remote machine is not set. I'm not sure what the workaround might be but this plugin is dependent on this variable being set to work.

UPDATE After taking a closer look at the code, vim-tmux-navigate is supposed to call vim's wincmd when $TMUX is not empty. It appears that, tmux intercepts the key stroke before vim can act on it.

sdondley commented 3 years ago

Here's a workaround I'm using. I simply remapped which keys move up/down/left/right:

let g:tmux_navigator_no_mappings = 0
nnoremap <silent> <leader>h :TmuxNavigateLeft<cr>
nnoremap <silent> <leader>j :TmuxNavigateDown<cr>
nnoremap <silent> <leader>k :TmuxNavigateUp<cr>
nnoremap <silent> <leader>l :TmuxNavigateRight<cr>

Not ideal because you have to stop and think about which kind of panes you want to move between but it beats using ctrl-w.