1

I'm using vim with tmux.

I setup seemless pane switching between Vim splits and Tmux splits

With commands like this:

bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"

In my tmux config and it works great.

However, it breaks when I use git to start vim. For example:

git difftool --tool=vimdiff --no-prompt filename.rb

This command starts vim, but since it's through git seemless pane switching doesn't work because it looks to see is the pane is running process "vim" and it is not (it registers as "git").

Does anyone know of a way to fix this?

newUserNameHere
  • 17,348
  • 18
  • 49
  • 79

2 Answers2

1

Here is my solution, it's a bit hacky but it works

I created a file called ~/vdif

and then an alias alias vdif="~/vdif so I can call it from wherever

In this file I put the following:

printf "\033]2;%s\033\\" "vim"
git difftool --no-prompt --tool=vimdiff $1 $2
printf "\033]2;%s\033\\" "bash"

The first line sets the pane_title to "vim", the second opens the git diff, the third lines sets page title to "bash" upon exit.

Then in my tmux config I added the following to check both the pane_title and pane_current_command option to see if vim exists:

is_vim='echo "#{pane_current_command}#{pane_title}" | grep -iqE "vim"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
newUserNameHere
  • 17,348
  • 18
  • 49
  • 79
  • how did you come up with that solution? original thought/work? It's really cool! - I first read about it here: https://www.bugsnag.com/blog/tmux-and-vim – PandasRocks Jan 17 '20 at 19:41
0

If you use https://github.com/christoomey/vim-tmux-navigator

and set the bindings yourself. You can change the line is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?x?)(diff)?$"' to is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(git|view|n?vim?x?)(diff)?$"'

Notice the git| addition in the regular expression? That will help check if you are using git difftool.

joerideg
  • 1,818
  • 1
  • 15
  • 18