Switching panes within Git's Vimdiff in Tmux

newUserNameHere

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

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"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Switching panes within Git's Vimdiff in Tmux

From Dev

how to end tmux sequence after switching panes

From Dev

Switching tmux zoom between panes without zooming out

From Dev

What's the difference between vimdiff and vimdiff2 in git?

From Dev

Cycling through tmux panes

From Dev

tmux split into 4 panes

From Dev

tmux / vim split panes

From Dev

Buttons for new panes in tmux

From Dev

JAVAFX: Switching Between Panes in BorderPane

From Dev

Tmux Split Panes in the same window

From Dev

tmux: rotate panes vertically or horizontally

From Dev

tmux: merge all windows as panes

From Dev

tmux with more terminals than panes

From Dev

Vimdiff and git all at once

From Dev

User switching within a Docker container's context

From Dev

How to convert 2 horizontal panes to vertical panes in tmux?

From Dev

Switching tab panes on selection option change

From Dev

tmux: How to automatically open sessions, windows, and panes

From Dev

How to navigate between panes in vim and tmux

From Dev

Is there a way to get the active pane ID for tmux panes

From Dev

How does one swap two panes in Tmux?

From Dev

In tmux, is it possible to list all panes in all windows?

From Dev

How to resize tmux panes inside tty

From Dev

how to close all panes but the current pane in tmux

From Dev

How to navigate between panes in vim and tmux

From Dev

In tmux, is it possible to list all panes in all windows?

From Dev

tmux: Switch windows and panes with a single key

From Dev

How not to switch past the edge of panes in tmux

From Dev

tmux two seperate panes with some process