Browse Source

[tmux/vim] Use vim-tmux-navigator for seemless navigation between vim splits and tmux panes.

master
Fredrik Ekre 3 years ago
parent
commit
35b203a71a
  1. 24
      .tmux.conf
  2. 8
      .vimrc

24
.tmux.conf

@ -11,11 +11,25 @@ set-option -g renumber-windows on @@ -11,11 +11,25 @@ set-option -g renumber-windows on
# see https://github.com/neovim/neovim/wiki/FAQ#esc-in-tmux-or-gnu-screen-is-delayed
set -sg escape-time 0
# vim keys for switching between panes
bind-key -r k select-pane -U
bind-key -r j select-pane -D
bind-key -r h select-pane -L
bind-key -r l select-pane -R
# 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'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"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
# vim mode keys in copy-mode
set-window-option -g mode-keys vi

8
.vimrc

@ -24,6 +24,9 @@ call plug#begin('~/.vim/plugged') @@ -24,6 +24,9 @@ call plug#begin('~/.vim/plugged')
" Send code to REPL
Plug 'jpalardy/vim-slime'
" Seemless vim/tmux navigation
Plug 'christoomey/vim-tmux-navigator'
if has('nvim')
" LSP helpers
Plug 'neovim/nvim-lspconfig'
@ -79,11 +82,6 @@ call plug#end() @@ -79,11 +82,6 @@ call plug#end()
:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab smarttab autoindent "Nicer tab actions
"Highlight without moving
:nnoremap * *``
"Move aroung splits without the C-W prefix
:nnoremap <C-J> <C-W><C-J>
:nnoremap <C-K> <C-W><C-K>
:nnoremap <C-L> <C-W><C-L>
:nnoremap <C-H> <C-W><C-H>
"Easier fzf keybindings
:nnoremap <C-F> :Rg!<CR>
:nnoremap <expr> <C-P> (len(system('git rev-parse')) ? ':Files!' : ':GFiles!')."<CR>"

Loading…
Cancel
Save