tmux and Vim splits

Developers often use tmux panes and Vim windows to complement each other. You can have Vim open in different tmux panes as a way to isolate Vim instances from each other (and therefore group buffers). Normally, I have a few tmux panes open with Vim in one of them (with its own splits as needed), and shell running in the rest. Everyone treats their panes and windows differently, and you may want to experiment.

tmux and Vim use different key bindings to navigate through windows (or, in tmux terminology, panes). This is rather confusing, and there are solutions in place to fix it! The easiest is to use the vim-tmux-navigator plugin, which is available from https://github.com/christoomey/vim-tmux-navigatorvim-tmux-navigator adds support for consistent navigation between Vim windows and tmux panes using the Ctrl hCtrl jCtrl k, and Ctrl l keys.

In order to use vim-tmux-navigator, your tmux needs to be version 1.8 or higher. You can check your tmux version by running the following:

$ tmux -V

See the previous tmux section for tips on how to install a newer version of tmux.
If you're using vim-plug, you can install vim-tmux-navigator by adding the following line to your .vimrc file:

Plug 'christoomey/vim-tmux-navigator'

Don't forget to run :w | source $MYVIMRC | PlugInstall to install the plugin.

Once you have the plugin installed, you'll have to add the following bindings to your ~/.tmux.conf file (this snippet is available from https://github.com/christoomey/vim-tmux-navigator):

# 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 -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

If you're an advanced tmux user, or don't mind digging around, you may want to use TPM (Tmux Plugin Manager) instead of pasting the snippet into your .tmux.conf file. Add the following lines to .tmux.conf for TPM to configure the plugin for you:

set -g @plugin 'christoomey/vim-tmux-navigator'
run '~/.tmux/plugins/tpm/tpm'

You can learn more about TPM (and how to install it) from https://github.com/tmux-plugins/tpm.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.86.172