Fix navigation annoyances

Fixes #6 by setting a window option called `vim$TMUX_PANE` during vim
setup, and removing it when vim exits:

```vim
if $TMUX !=# ''
  " Set tmux window option to detect when to change pane.
  let s:tmux_option = '@vim'.substitute($TMUX_PANE, '%', '\\%', 'g')
  call system('tmux set-window-option '.s:tmux_option.' 1')
  au VimLeave * call system('tmux set-window-option -u '.s:tmux_option)
endif
```

Then update the `is_vim` conditional shell statement to check if this
variables exists for the current pane to determine when to change tmux
pane or pass through the binding to vim.

```conf
in_vim='[[ "$(tmux show-window-options)" = *"@vim#{pane_id}"* ]] && \
        [[ "#{pane_current_command}" != zsh ]]'
```

Additionally check if the vim task has been backgrounded by comparing
the value of `#{pane_current_command}`, this is likely a bit brittle if
backgrounding is used heavily but works otherwise.
This commit is contained in:
Kenneth Benzie 2019-08-11 18:42:57 +01:00
parent b47c74a33f
commit 56739ba2e7

View File

@ -62,14 +62,13 @@ bind '"' split-window -c '#{pane_current_path}'
bind '%' split-window -h -c '#{pane_current_path}' bind '%' split-window -h -c '#{pane_current_path}'
# Integrate pane selection with vim # Integrate pane selection with vim
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?$"' in_vim='[[ "$(tmux show-window-options)" = *"@vim#{pane_id}"* ]] && \
unbind -T copy-mode-vi C-h [[ "#{pane_current_command}" != zsh ]]'
unbind -T copy-mode-vi C-j bind -n C-h if $in_vim 'send-keys C-h' 'select-pane -L'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L" bind -n C-j if $in_vim 'send-keys C-j' 'select-pane -D'
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D" bind -n C-k if $in_vim 'send-keys C-k' 'select-pane -U'
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U" bind -n C-l if $in_vim 'send-keys C-l' 'select-pane -R'
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R" bind -n C-\ if $in_vim 'send-keys C-\\' 'select-pane -l'
bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# Integrate urlview # Integrate urlview
bind u capture-pane \; split-window 'tmux show-buffer | urlview -' bind u capture-pane \; split-window 'tmux show-buffer | urlview -'