christoomey / vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
MIT License
5.07k stars 319 forks source link

Navigating vim splits doesn't work properly. #317

Open Zerophase opened 2 years ago

Zerophase commented 2 years ago

How to reproduce.

  1. Have two tmux panes split vertically.
  2. Open vim on the right pane
  3. split vim with vsplit
  4. Switch to the left tmux pane with ctrl-h.
  5. Press ctrl-h again

You'll switch to the last active vim split, instead of wrapping around to the split furthest to the right.

dattran1232003 commented 2 years ago

Same here

azinsharaf commented 1 year ago

same here. It moves between tmux panes. It also moves from tmux pane to neovim pane and visa versa. But it doesn't move between neovim panes itself.

christoomey commented 1 year ago

Hey folks, could you run through the troubleshooting list, notably the TmuxNavigatorProcessList bit? I'm wondering if something may be up with neovim in recent versions (see https://github.com/christoomey/vim-tmux-navigator/issues/324 for a potentially related issue).

azinsharaf commented 1 year ago

:TmuxNavigatorProcessList is not an option in my neovim setup.

image

christoomey commented 1 year ago

Hmm, are you perhaps on a very old version of the vim plugin? :TmuxNavigatorProcessList was added in mid 2018, so possible you're version predates that @azinsharaf?

azinsharaf commented 1 year ago

I doubt it since i installed it recently. How can I check its version?

christoomey commented 1 year ago

Definitely odd then. Can you try running :TmuxNavigatorProcessList directly? Your screenshot is showing tab completion and I'm wondering if the prefix :TmuxNavigate... vs TmuxNavigator... being different might explain why you're not seeing it.

Alternatively you could track down where your vim plugins are installed and look at the contents of the file itself to see if it matches what's on github right now.

azinsharaf commented 1 year ago

:TmuxNavigatorProcessList is not an editor command. I am wondering how it works for @Zerophase and @dattran1232003.

azinsharaf commented 1 year ago

@christoomey i am using Neovim v0.8.0. Does the plugin support neovim?

christoomey commented 1 year ago

The plugin is definitely intended to support Neovim. I'm surprised to see that it's not working. Can you track down the installed version of the plugin on your machine and confirm if it matches the version on Github? Specifically this line is the one that defines the command in question.

azinsharaf commented 1 year ago

I re-installed it and have the same issue. Confirming that i am using the latest version. This is a gif file about how it looks like:

neovim

christoomey commented 1 year ago

Yup, I can definitely see what you're reporting. Unfortunately not much more for me to go from in the gif.

Can you track down the installed version of the plugin code on your machine and confirm if it matches the version on Github? Specifically this line is the one that defines the command in question.

lambda0xff commented 1 year ago

Exact same issue here.

TmuxNavigatorProcessList gives: Ss+ /bin/zsh (figterm)

lambda0xff commented 1 year ago

Probably same issue a https://github.com/christoomey/vim-tmux-navigator/issues/295 ?

Copy-Paste fix that works for me: In .tmux.conf, replace is_vim with:

is_vim="children=(); i=0; pids=( $(ps -o pid= -t '#{pane_tty}') ); \
while read -r c p; do [[ -n c && c -ne p && p -ne 0 ]] && children[p]+=\" $\{c\}\"; done <<< \"$(ps -Ao pid=,ppid=)\"; \
while (( $\{#pids[@]\} > i )); do pid=$\{pids[i++]\}; pids+=( $\{children[pid]-\} ); done; \
ps -o state=,comm= -p \"$\{pids[@]\}\" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

ps: this works, but seems to have some impact on performance

geralfonso commented 1 year ago

Exact same issue here.

TmuxNavigatorProcessList gives: Ss+ /bin/zsh (figterm)

I had the same issue but in my case, it was caused by https://fig.io/. I uninstalled it and now it's working as expected.

popoffvg commented 1 year ago

I fixed the issue using this tip

Added lines in .tmux.conf

# smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"
azinsharaf commented 1 year ago

didn't work for me. Interested to see how it works for others.

johnoshea commented 1 year ago

Are you running a poetry shell by any chance? I see the same problem (navigating inside Neovim doesn't work, but does between Neovim and tmux) but only if I've run poetry shell before starting Neovim.

FWIW, the output of :TmuxNavigatorProcessList with a poetry shell running:

Ss   -zsh
S    -zsh
S    /Users/johno/.cache/gitstatus/gitstatusd-darwin-arm64
S+   /opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python

and without poetry shell running:

Last login: Fri Nov 25 22:42:57 on ttys000
Ss   -zsh
S    -zsh
S    /Users/johno/.cache/gitstatus/gitstatusd-darwin-arm64
S+   nvim
sspaeti commented 1 year ago

I can confirm I used it for a while without any problem. As soon as I run poetry shell, I can't switch inside neovim anymore, only between tmux windows. I can create a new window again and without poetry, it works again.

TmuxNavigatorProcessList when it does not work any longer :(

Ss   -zsh
S    -zsh
S    -zsh
S    -zsh
S    /Users/sspaeti/.cache/gitstatus/gitstatusd-darwin-arm64
S+   /opt/homebrew/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python

Anything I can workaround this?

Found the same error mentioned in https://github.com/christoomey/vim-tmux-navigator/issues/230#issuecomment-1317678653. The workaround seems to much for me though, but also didn't work. I'm using Python with venvs all the time without problems, I'm not sure why poetry behaves differently here.

johnoshea commented 1 year ago

In my case, it looks like I've got $SHELL pointing at the OS-default zsh (/bin/zsh) which isn't the zsh I'm actually using (Homebrew-installed, /opt/homebrew/bin/zsh). Here's some heavily trimmed output showing my normal zsh (top half) and the zsh run by poetry (bottom half):

❯ ps
  PID TTY           TIME CMD
...
 1154 ttys000    0:00.01 tmux -f /Users/johno/.tmux.conf attach
 1372 ttys001    0:21.85 -zsh
...

87818 ttys007    0:00.47 /bin/zsh -i

Setting $SHELL to either just zsh on its own, or the full path to the Homebrew zsh seems to have resolved this, though I've only tested this for 10 minutes or so.

sspaeti commented 1 year ago

@johnoshea Wow, that is a big one; thanks for that, I never noticed this! It did not work for me :( But I added the export SHELL=zsh to my .zshrc anyway, as I guess that should be more correct, although I hadn't had any problem otherwise.

My workaround, for now, is that I have alternative moving shortcuts for vim that I can use in case I bump into that problem with:

"Move window
noremap sh <C-w>h
noremap sk <C-w>k
noremap sj <C-w>j
noremap sl <C-w>l
juliangoetze commented 1 year ago

Exact same issue here. TmuxNavigatorProcessList gives: Ss+ /bin/zsh (figterm)

I had the same issue but in my case, it was caused by https://fig.io/. I uninstalled it and now it's working as expected.

I had the same problem with https://fig.io/ and uninstalling fig worked for me too. I guess this issue is worth searching for a solution, because I neither want to dispense with fig nor the vim-tmux-navigation... I will open up an issue on that one

tcrundall commented 9 months ago

I feel like @Zerophase 's issue is different to all the subsequent replies, and it's their issue I'm currently facing. Though after looking into both the vim plugin and the tmux binding implementations, I believe what Zerophase and I both want to happen simply isn't part of tmux-vim-navigator's intended behaviour.

When switching from a tmux pane without vim into a tmux pane with vim (i.e. a tmux-vim-pane), if the tmux-vim-pane has multiple vim panes itself, I'd like to switch into the closest of those vim-panes (if this is confusingly described, Zerophase's original comment already gives a simple case example).

So far as I understand, it is the intended behaviour that: when switching into a tmux-vim-pane, the vim-pane that will be selected will be whichever one was last active when this tmux-vim-pane was last active. And therefore not necessarily the vim-pane adjacent to the tmux-pane I just left.

If this is true, please confirm and perhaps update the readme to reflect this.

nazariyv commented 5 months ago

Just reporting that poetry shell is causing problems for me as well. When I have nvim tree on the very left and some code next to it, with a vertical split, keybindings to move between tmux and nvim will only work in one of the following ways:

1/ if I were focused on nvim-tree, then keybinding will take me to tmux. Then again to nvim-tree 2/ if I were focused on code, then keybinding will take me to tmux. Then again to code

The above happens if poetry shell before starting nvim.

If I do not poetry shell, I can move correctly from nvim-tree to code to tmux and back.

Curious fact, if executing :TmuxNavigateLeft directly (or another navigation command), it all works well.

nazariyv commented 5 months ago

Just reporting that poetry shell is causing problems for me as well. When I have nvim tree on the very left and some code next to it, with a vertical split, keybindings to move between tmux and nvim will only work in one of the following ways:

1/ if I were focused on nvim-tree, then keybinding will take me to tmux. Then again to nvim-tree 2/ if I were focused on code, then keybinding will take me to tmux. Then again to code

The above happens if poetry shell before starting nvim.

If I do not poetry shell, I can move correctly from nvim-tree to code to tmux and back.

Curious fact, if executing :TmuxNavigateLeft directly (or another navigation command), it all works well.

https://github.com/christoomey/vim-tmux-navigator/issues/230#issuecomment-776097681

poetry run nvim seems to fix this issue

miklhh commented 4 months ago

I also start to feel like @Zerophase's original issue isn't being addressed here anymore. I'm curious if there is going effort in trying to add the original feature (if possible at all). I also feel like, whether it is possible to or not, that the issue at hand should be addressed somewhere. Possibly in the vim-tmux-navigator README.

I would love @christoomey's thoughts on the original issue as well.

unkindypie commented 2 months ago

I have the same issue when running vim from poetry

anousonefs commented 2 months ago

same here on mac m3