Search code examples
shellvitmux

Multiple copy buffers in tmux's vi copy mode


Vi has named buffers by typing "[a-z], followed by your yank/delete/etc command. Does tmux's vi copy-mode have named buffers? I'd like to copy various strings into different tmux buffers and be able to paste them individually


Solution

  • Yes, it does.

    man tmux /^BUFFERS or the web copy:

    tmux maintains a set of named paste buffers. Each buffer may be either explicitly or automatically named. Explicitly named buffers are named when created with the set-buffer or load-buffer commands, or by renam‐ ing an automatically named buffer with set-buffer -n. Automatically named buffers are given a name such as ‘buffer0001’, ‘buffer0002’ and so on. When the buffer-limit option is reached, the oldest automati‐ cally named buffer is deleted. Explicitly named buffers are not sub‐ ject to buffer-limit and may be deleted with delete-buffer command.

    Buffers may be added using copy-mode or the set-buffer and load-buffer commands, and pasted into a window using the paste-buffer command. If a buffer command is used and no buffer is specified, the most recently added automatically named buffer is assumed.

    ...

    The buffer commands are as follows:

    ...

    load-buffer [-b buffer-name] path
                   (alias: loadb)
             Load the contents of the specified paste buffer from path.
    
    paste-buffer [-dpr] [-b buffer-name] [-s separator] [-t target-pane]
                   (alias: pasteb)
             Insert the contents of a paste buffer into the specified pane.
             If not specified, paste into the current one.  With -d, also
             delete the paste buffer.  When output, any linefeed (LF) char‐
             acters in the paste buffer are replaced with a separator, by
             default carriage return (CR).  A custom separator may be speci‐
             fied using the -s flag.  The -r flag means to do no replacement
             (equivalent to a separator of LF).  If -p is specified, paste
             bracket control codes are inserted around the buffer if the
             application has requested bracketed paste mode.
    

    I truncated some of the information (including other buffer commands); definitely take a look at the website above (or the man page) for how to use these tools.