Enable Vim mode in tmux by adding set-window-option -g mode-keys vi
to your ~/.tmux.conf
file. This allows you to use vi-style keybindings in copy mode for navigation and text selection.
set-window-option -g mode-keys vi
tmux's copy mode supports two sets of keybindings: Emacs-style (default) and Vi-style. By enabling Vi mode, you can use familiar Vim navigation and selection commands in tmux, which is especially useful for Vim users.
Add the following line to your ~/.tmux.conf
file:
# Enable Vi mode set-window-option -g mode-keys vi # Or the shorter version setw -g mode-keys vi
After enabling Vi mode and entering copy mode (Ctrl+b [), you can use these key bindings:
Enhance Vi mode by adding these keybindings to your ~/.tmux.conf
:
# Setup 'v' to begin selection, just like Vim bind-key -T copy-mode-vi v send-keys -X begin-selection # Setup 'y' to yank (copy), just like Vim bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel # Update the default binding of 'Enter' to use copy-selection-and-cancel unbind-key -T copy-mode-vi Enter bind-key -T copy-mode-vi Enter send-keys -X copy-selection-and-cancel
Make Vi mode even more powerful by integrating with your system clipboard:
# For macOS bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy" # For Linux with xclip bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard" bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
If you use Neovim or Vim inside tmux, add this to your ~/.tmux.conf
to reduce escape key delay:
# Reduce delay when pressing Escape in Vim set -sg escape-time 10
When using Vi mode in tmux, you may need to explicitly set Vim's "term" variable for proper color support. Add this to your ~/.vimrc
or ~/.config/nvim/init.vim
:
set -g default-terminal "screen-256color"