115

I run Tmux in Vi mode. Vi-like navigation in copy mode works fine. However, I can't select any text. Neither v nor V switches to Vi-like text selecting mode.

What am I missing?

By the way, is it possible to display line numbers in copy mode?

P.S.: I'm running Tmux on Mac OS with Z shell

5 Answers 5

134

Short answer: space starts selection and enter copies.

For future reference, I got this from the tmux man page:

       Function                vi             emacs
       Back to indentation     ^              M-m
       Clear selection         Escape         C-g
       Copy selection          Enter          M-w
       Cursor down             j              Down
       Cursor left             h              Left
       Cursor right            l              Right
       Cursor to bottom line   L
       Cursor to middle line   M              M-r
       Cursor to top line      H              M-R
       Cursor up               k              Up
       Delete entire line      d              C-u
       Delete to end of line   D              C-k
       End of line             $              C-e
       Goto line               :              g
       Half page down          C-d            M-Down
       Half page up            C-u            M-Up
       Next page               C-f            Page down
       Next word               w              M-f
       Paste buffer            p              C-y
       Previous page           C-b            Page up
       Previous word           b              M-b
       Quit mode               q              Escape
       Scroll down             C-Down or J    C-Down
       Scroll up               C-Up or K      C-Up
       Search again            n              n
       Search backward         ?              C-r
       Search forward          /              C-s
       Start of line           0              C-a
       Start selection         Space          C-Space
       Transpose chars                        C-t

Update: The tmux list-keys command will also list any custom key bindings you have.

3
  • 4
    Additional tip, you can check which tmux copy mode you are currently using with: tmux show-options -gw | grep mode-keys. If you want to change the mode permanently, add this line to ~/.tmux.conf: setw -g mode-keys vi (or emacs). Then run tmux source ~/.tmux.conf to apply it.
    – wisbucky
    Jul 10, 2020 at 18:47
  • for some reason w does not respect punctuation and enter does not copy on Mac Aug 30, 2022 at 15:45
  • How do you paste the text afterwards, after tmux exits copy mode?
    – szx
    Oct 11, 2022 at 12:47
111

You use space bar for the beginning of the selection and enter for the end.

copy:

  • Ctrlb[
  • Space
  • Enter

paste:

  • Ctrlb]
7
  • 2
    This should be the answer. It could be improved by explaining entering/leaving copy mode.
    – mcsilvio
    Mar 25, 2015 at 1:19
  • 3
    Great, brief answer. Just a note to fellow vi[m] neophytes: If you're using a modal editor or command line, you're going to want to make sure you're in insert mode before attempting to paste using the aformentioned Ctrl+b+]. Obvious in retrospect, but sent me back and forth a few times until I cottoned on. Aug 7, 2016 at 19:32
  • I think the formatting and conciseness would be an awesome replacement for the the "short answer" section in my answer. Is there a way to combine answers that gives credit where credit is due?
    – jmhmccr
    Oct 28, 2017 at 21:45
  • hmm... thinking further, I guess two answers are more appropriate, would just like to have this above the fold somehow.
    – jmhmccr
    Oct 28, 2017 at 21:53
  • is this expected to work with nano? When I press <kbd>space</kbd>, I just get the cursor on the bottom of the tmux panel.
    – YakovL
    Jun 7, 2022 at 11:17
38

Upstream (2.4+) tmux changed how to bind for begin selection. To create a binding for what the OP is asking use -T and send-keys with -X:

# Use v to trigger selection    
bind-key -T copy-mode-vi v send-keys -X begin-selection

# Use y to yank current selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
2
  • My tmux copy-mode just stopped working completely and I couldn't work it out, this fixed it.
    – GTF
    May 9, 2017 at 13:35
  • 2
    tmux upgrades break my configs more often than I'd like... :-( Sep 25, 2017 at 7:49
30

You can also set up your .tmux.conf file by adding :

bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection

which will enable 'v' and 'y' to enter visual mode and copy, like in vim.

(Source)

4
  • 1
    I'm getting "command not found: bind-key" in tmux 1.9a Jan 9, 2015 at 7:01
  • 1
    Oops, I put it in my .zshrc by accident, nvm :) Jan 9, 2015 at 7:06
  • 16
    This stuff's changed in newer Tmux versions. It's now bind-key -T copy-mode-vi ...
    – Steven Lu
    Jan 20, 2017 at 19:11
  • 2
    see above superuser.com/a/1204738/48390 for up-to-date solution with newer Tmux versions
    – abernier
    Oct 19, 2021 at 14:07
5

I find entering vi mode easily to be my bottleneck for which I use the following:

setw -g mode-keys vi
set-window-option -g mode-keys vi  
unbind [
bind-key -n F2 copy-mode

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .