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

Movement within vim splits does not work on remote #238

Open
jessebett opened this issue Jul 25, 2019 · 5 comments
Open

Movement within vim splits does not work on remote #238

jessebett opened this issue Jul 25, 2019 · 5 comments

Comments

@jessebett
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link

miker985 commented Sep 5, 2019

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
Copy link
Contributor

sdondley commented Aug 29, 2021

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
Copy link
Contributor

sdondley commented Aug 29, 2021

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.

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

4 participants