Summary of copy-mode for copying with vi operation in tmux#

When connecting to a remote Ubuntu via SSH and working on tmux, it is very convenient to be able to copy using Vim-like operations. In this article, we will use copy-mode in tmux to introduce how to select and copy strings using just the keyboard without using the mouse.

Prerequisite environment#

  • Windows Terminal (client side)

  • SSH connection destination is Ubuntu

  • tmux version 1.9 or higher recommended

tmux initial settings (.tmux.conf)#

By writing the following contents in ~/.tmux.conf, vi operation and mouse support will be possible.

# Vim風キーバインドを有効に
setw -g mode-keys vi

# マウス操作を有効に(必要に応じて)
set -g mouse on

For the settings to take effect, run the following within a tmux restart or session:

tmux source-file ~/.tmux.conf

Keyboard copy procedure using copy-mode#

  1. enter copy-mode

    Ctrl + b → [
    
  2. Move the cursor (Vim style)

    • h, j, k, l: Move left/down/up/right

    • w, b : Move by word

    • 0, $ : Start of line, end of line

    • g, G: beginning, end of buffer

  3. Start range selection

    Space
    
  4. Confirm copy

    Enter
    
  5. When pasting

    Ctrl + b → ]
    

About copying to Windows side#

The tmux buffer is located on the Ubuntu side, so it cannot be copied directly to the Windows clipboard.

Alternative:

  • Copy with Windows Terminal mouse selection + right click

  • Export to a file on tmux and obtain with scp or VSCode Remote

  • Send to the host side using xclip or wl-copy on the Linux side (if there is a GUI)

summary#

operation

Content

Ctrl + b[

enter copy-mode

Vim operations (hjkl, w, b, etc.)

Move cursor

Space

Start range selection

Enter

copy selection

Ctrl + b]

Paste the copied content (inside tmux)

If you know and get used to this operation, you will be able to work more efficiently on tmux. I definitely want to get used to it.

Article information

author:

Mr. Takagi

Post date:

2025-05-20