Simple Tutorial

This article records a minimal tmux configuration tutorial for basic development needs.

First open the tmux configuration file:

1vim ~/.tmux.conf

Then type the following content:

set-option -g automatic-rename on
set-option -g aggressive-resize on
set-option -g mouse on

set-option -g base-index 1
set-option -g pane-base-index 1

Final tmux Configuration

Here we use the configuration from https://github.com/gpakosz/.tmux. The commands are:

cd
git clone https://github.com/gpakosz/.tmux.git
ln -s -f .tmux/.tmux.conf
cp .tmux/.tmux.conf.local .

Edit ~/.tmux.conf.local and change the value of tmux_conf_copy_to_os_clipboard to true. The code is:

# -- clipboard -----------------------------------------------------------------

# in copy mode, copying selection also copies to the OS clipboard
#   - true
#   - false (default)
# on macOS, this requires installing reattach-to-user-namespace, see README.md
# on Linux, this requires xsel or xclip
tmux_conf_copy_to_os_clipboard=true

Enable mouse mode by uncommenting #set -g mouse on. The code is:

# start with mouse mode enabled
set -g mouse on

On Linux, you need to install xsel or xclip. The commands are:

# ubuntu:
sudo apt install xsel
# sudo apt install clip

# arch
sudo pacman -S xclip

Reopen tmux or reload the configuration with prefix + r.

Fixing Slow nvim Startup in WSL Caused by the Clipboard

After enabling the shared clipboard above, for some reason nvim started much more slowly. Eventually I found clipboard-related errors, and then found a post on CSDN:

Original post: How to fix slow startup after adding clipboard = “unnamedplus” to Neovim

While recently reconfiguring neovim in WSL, I found that startup became very slow. After spending a lot of time, I finally found the cause. Commenting out vim.opt.clipboard = "unnamedplus" in the configuration file (init.lua or options.lua) makes startup normal again.

Of course, we know that vim.opt.clipboard = "unnamedplus" exists so that Vim uses the system clipboard register for copy (yank) and paste operations. But simply commenting it out would greatly reduce nvim’s usefulness.

You can try commenting out vim.opt.clipboard = "unnamedplus" and see whether the speed recovers. The steps are:

  1. Download win32yank.exe with the following commands:
curl -sLo/tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/download/v0.1.1/win32yank-x64.zip
unzip -p /tmp/win32yank.zip win32yank.exe > /tmp/win32yank.exe
sudo chmod +x /tmp/win32yank.exe
sudo mv /tmp/win32yank.exe /usr/local/bin/
sudo rm -rf /tmp/win32yank.zip

Verify that it works correctly:

# Set the clipboard

    echo "hello brave new world!" | win32yank.exe -i
    
# Get the clipboard.

    win32yank -o

If there is no output, use the link above to manually download win32yank.exe to Windows and then copy it over with the following command:

# Assume you are now in the download directory and have extracted it
sudo mv /mnt/c/User/your-user-name/Downloads/win32yank/win32yank.exe /usr/local/bin/
  1. Put the following content into init.lua:
vim.g.clipboard = {
    name = 'win32yank-wsl',
    copy = {
        ['+'] =  'win32yank.exe -i --crlf',
        ['*'] =  'win32yank.exe -i --crlf',
    },
    paste = {
        ['+'] = 'win32yank.exe -o --lf',
        ['*'] = 'win32yank.exe -o --lf',
    },
    cache_enabled = true,
}

However, on some machines win32yank performs poorly, so you can decide whether to enable this feature based on your situation.

Common Tips

The prefix key is ctrl + b.

  • Copy content from a tmux window to the clipboard: hold Shift, use the left mouse button to select, and if window scrolling is not enabled, type prefix + [;
  • Create a new tmux session: prefix + : + new -s name;