My vim configuration
git clone https://github.com/m-col/vim-misc
Files | Refs | Readme

Commit a843684fd262a0ad465cada132c7f27cd809fd68
Parent: a76d4fc2550bb8b105753ef0ddf84dd2ca5c9f29
Author: mcol <mcol@posteo.net>
Date: 2019-03-12 23:02:43 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2019-03-12 23:02:43 +0000

trying new vim-tmux navigation without plugin

vimrc Modified

@@ -26,7 +26,7 @@
 Plugin 'junegunn/goyo.vim'
 Plugin 'mcolligan/vim-misc'		    " my vimrc and misc functions 
 Plugin 'mcolligan/tide'			    " tmux ide
-Plugin 'christoomey/vim-tmux-navigator'	    " navigate vim and tmux splits seamlessly
+"Plugin 'christoomey/vim-tmux-navigator'	    " navigate vim and tmux splits seamlessly
 
 call vundle#end()			    " required
 filetype plugin indent on		    " required
@@ -114,3 +114,9 @@
 
 " session saving
 let g:vimlab_session = "~/.vim/sessions/matlab-session.vim"
+
+" Intelligently navigate tmux panes and Vim splits using the same keys.
+" See https://sunaku.github.io/tmux-select-pane.html for documentation.
+let progname = substitute($VIM, '.*[/\\]', '', '')
+set title titlestring=%{progname}\ %f\ +%l\ #%{tabpagenr()}.%{winnr()}
+if &term =~ '^screen' && !has('nvim') | exe "set t_ts=\e]2; t_fs=\7" | endif

tmux.conf Modified

@@ -7,11 +7,10 @@
 
 # bindings
 bind r source-file ~/.tmux.conf
-#bind-key C-a last-window
-bind-key | split-window -hb \; run-shell "~/.vim/bundle/vim-misc/bsptm"
-#bind-key -n C-d kill-pane \; run-shell "~/.vim/bundle/vim-misc/bsptm"
 bind C-l send-keys 'C-l'
 bind C-a send-keys 'C-a'
+bind-key | split-window -hb \; run-shell "~/.vim/bundle/vim-misc/bsptm"
+set-hook -g pane-exited 'run-shell "~/.vim/bundle/vim-misc/bsptm"'
 
 # general settings
 set -g default-terminal "rxvt-unicode-256color"
@@ -41,17 +40,88 @@
 #setw -g window-status-format ' #I#[fg=colour7]:#[fg=colour8]#W#[fg=colour7]#F '
 set -g status off
 
-# Smart pane switching with awareness of Vim splits.
-# See: https://github.com/christoomey/vim-tmux-navigator
-is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
-    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
-bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
-bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
-bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
-bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
-bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
-bind-key -T copy-mode-vi C-h select-pane -L
-bind-key -T copy-mode-vi C-j select-pane -D
-bind-key -T copy-mode-vi C-k select-pane -U
-bind-key -T copy-mode-vi C-l select-pane -R
-bind-key -T copy-mode-vi C-\ select-pane -l
+## Smart pane switching with awareness of Vim splits.
+## See: https://github.com/christoomey/vim-tmux-navigator
+#is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
+#    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
+#bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
+#bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
+#bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
+#bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
+#bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
+#bind-key -T copy-mode-vi C-h select-pane -L
+#bind-key -T copy-mode-vi C-j select-pane -D
+#bind-key -T copy-mode-vi C-k select-pane -U
+#bind-key -T copy-mode-vi C-l select-pane -R
+#bind-key -T copy-mode-vi C-\ select-pane -l
+
+
+# Intelligently navigate tmux panes and Vim splits using the same keys.
+# See https://sunaku.github.io/tmux-select-pane.html for documentation.
+#
+#      +-------------+------------+-----------------------------+
+#      | inside Vim? | is Zoomed? | Action taken by key binding |
+#      +-------------+------------+-----------------------------+
+#      | No          | No         | Focus directional tmux pane |
+#      | No          | Yes        | Nothing: ignore key binding |
+#      | Yes         | No         | Seamlessly focus Vim / tmux |
+#      | Yes         | Yes        | Focus directional Vim split |
+#      +-------------+------------+-----------------------------+
+#
+vim_navigation_timeout=0.05 # number of seconds we give Vim to navigate
+navigate='                                                             \
+  pane_is_zoomed() {                                                   \
+    test #{window_zoomed_flag} -eq 1;                                  \
+  };                                                                   \
+  pane_title_changed() {                                               \
+    test "#{pane_title}" != "$(tmux display -p "##{pane_title}")";     \
+  };                                                                   \
+  command_is_vim() {                                                   \
+    case "${1%% *}" in                                                 \
+      (vi|?vi|vim*|?vim*|view|?view|vi??*) true ;;                     \
+      (*) false ;;                                                     \
+    esac;                                                              \
+  };                                                                   \
+  pane_contains_vim() {                                                \
+    case "#{=3:pane_current_command}" in                               \
+      (ssh|sh) command_is_vim "#{=5:pane_title}" ;;                    \
+      (*) command_is_vim "#{=5:pane_current_command}" ;;               \
+    esac;                                                              \
+  };                                                                   \
+  pane_contains_neovim_terminal() {                                    \
+    test "#{=12:pane_title}" = "nvim term://";                         \
+  };                                                                   \
+  navigate() {                                                         \
+    tmux_navigation_command=$1;                                        \
+    vim_navigation_command=$2;                                         \
+    vim_navigation_only_if=${3:-true};                                 \
+    if pane_contains_vim && eval "$vim_navigation_only_if"; then       \
+      if pane_contains_neovim_terminal; then                           \
+        tmux send-keys C-\\ C-n;                                       \
+      fi;                                                              \
+      eval "$vim_navigation_command";                                  \
+      if ! pane_is_zoomed; then                                        \
+        sleep $vim_navigation_timeout; : wait for Vim to change title; \
+        if ! pane_title_changed; then                                  \
+          eval "$tmux_navigation_command";                             \
+        fi;                                                            \
+      fi;                                                              \
+    elif ! pane_is_zoomed; then                                        \
+      eval "$tmux_navigation_command";                                 \
+    fi;                                                                \
+  };                                                                   \
+navigate '
+navigate_left=" $navigate 'tmux select-pane -L'  'tmux send-keys C-w h'"
+navigate_down=" $navigate 'tmux select-pane -D'  'tmux send-keys C-w j'"
+navigate_up="   $navigate 'tmux select-pane -U'  'tmux send-keys C-w k'"
+navigate_right="$navigate 'tmux select-pane -R'  'tmux send-keys C-w l'"
+navigate_back=" $navigate 'tmux select-pane -l || tmux select-pane -t1'\
+                          'tmux send-keys C-w p'                       \
+                          'pane_is_zoomed'                             "
+
+# QWERTY keys - comment these out if you don't use QWERTY layout!
+bind-key -n C-h run-shell -b "$navigate_left"
+bind-key -n C-j run-shell -b "$navigate_down"
+bind-key -n C-k run-shell -b "$navigate_up"
+bind-key -n C-l run-shell -b "$navigate_right"
+bind-key -n C-\ run-shell -b "$navigate_back"