tmux copy mode - select text block

Make sure to check the bottom of this post for necessary bindings that need to go into your .tmux.conf file.

I am assuming your prefix key is C-a:

  • C-a means: press Ctrl + A
  • C-a [ means: press Ctrl + A then press [

To do a rectangle selection of text from (1,1) to (2,2) in tmux:

  • Go to the copy mode: C-a [
  • Move the middle of a line
  • Press C-v
  • Press Space
  • Move the selection with jkhl
  • Once you are happy with your selection press Enter (or y if you have the binding in your conf file).
  • You can paste the latest copy buffer by: C-a ]

Notice that pressing space is necessary for rectangle selection.

To select lines like you would normally do, go the copy mode, and press v, select with jkhl keys and press y.

I have these bindings in my .tmux.conf:

Prior to version 2.4 (20 April 2017):

setw -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection     # Begin selection in copy mode.
bind-key -t vi-copy 'C-v' rectangle-toggle  # Begin selection in copy mode.
bind-key -t vi-copy 'y' copy-selection      # Yank selection in copy mode.

After version 2.4:

setw -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection     # Begin selection in copy mode.
bind-key -T copy-mode-vi 'C-v' send -X rectangle-toggle  # Begin selection in copy mode.
bind-key -T copy-mode-vi 'y' send -X copy-selection      # Yank selection in copy mode.

It is important to unbind default rectangle-toggle binding:

unbind-key -t vi-copy v  # Prior to version 2.4
unbind-key -T copy-mode-vi v

Otherwise new 'C-v' binding doesn't work.

Note: to have a single .tmux.conf which works across versions, see this question.


You can select a visual block just like in vi -- type v before starting the selection. In the manpage, this is called "Rectangle toggle".


As Lars points out, v actually does what you are asking for by toggling between rectangle mode and full-line selection mode. space and enter are used respectively to start a new selection and copy it. Enter copy mode using your prefix followed by [ and paste your copied selection into any tmux window using ]

This confused me also since v functions in vim as space does in tmux , to begin the selection.

Issuing :list-keys -t vi-copy in tmux will show the full table of commands in copy mode.

bind-key -t vi-copy    C-b page-up                                                      
bind-key -t vi-copy    C-c cancel
bind-key -t vi-copy    C-e scroll-down
bind-key -t vi-copy    C-f page-down
bind-key -t vi-copy    C-h cursor-left
bind-key -t vi-copy  Enter copy-selection
bind-key -t vi-copy    C-y scroll-up
bind-key -t vi-copy Escape clear-selection
bind-key -t vi-copy  Space begin-selection
bind-key -t vi-copy      $ end-of-line
bind-key -t vi-copy      , jump-reverse
bind-key -t vi-copy      / search-forward
bind-key -t vi-copy      0 start-of-line
bind-key -t vi-copy      1 start-number-prefix
bind-key -t vi-copy      2 start-number-prefix
bind-key -t vi-copy      3 start-number-prefix
bind-key -t vi-copy      4 start-number-prefix
bind-key -t vi-copy      5 start-number-prefix
bind-key -t vi-copy      6 start-number-prefix
bind-key -t vi-copy      7 start-number-prefix
bind-key -t vi-copy      8 start-number-prefix
bind-key -t vi-copy      9 start-number-prefix
bind-key -t vi-copy      : goto-line
bind-key -t vi-copy      ; jump-again
bind-key -t vi-copy      ? search-backward
bind-key -t vi-copy      B previous-space
bind-key -t vi-copy      D copy-end-of-line
bind-key -t vi-copy      E next-space-end
bind-key -t vi-copy      F jump-backward
bind-key -t vi-copy      G history-bottom
bind-key -t vi-copy      H top-line
bind-key -t vi-copy      J scroll-down
bind-key -t vi-copy      K scroll-up
bind-key -t vi-copy      L bottom-line
bind-key -t vi-copy      M middle-line
bind-key -t vi-copy      N search-reverse
bind-key -t vi-copy      T jump-to-backward
bind-key -t vi-copy      W next-space
bind-key -t vi-copy      ^ back-to-indentation
bind-key -t vi-copy      b previous-word
bind-key -t vi-copy      e next-word-end
bind-key -t vi-copy      f jump-forward
bind-key -t vi-copy      g history-top
bind-key -t vi-copy      h cursor-left
bind-key -t vi-copy      j cursor-down
bind-key -t vi-copy      k cursor-up
bind-key -t vi-copy      l cursor-right
bind-key -t vi-copy      n search-again
bind-key -t vi-copy      q cancel
bind-key -t vi-copy      t jump-to-forward
bind-key -t vi-copy      v rectangle-toggle
bind-key -t vi-copy      w next-word
bind-key -t vi-copy BSpace cursor-left
bind-key -t vi-copy  NPage page-down
bind-key -t vi-copy  PPage page-up
bind-key -t vi-copy     Up cursor-up
bind-key -t vi-copy   Down cursor-down
bind-key -t vi-copy   Left cursor-left
bind-key -t vi-copy  Right cursor-right
bind-key -t vi-copy   C-Up scroll-up
bind-key -t vi-copy C-Down scroll-down

Tags:

Vim

Tmux