Skip to content

Instantly share code, notes, and snippets.

@dwlamb
Last active July 27, 2023 19:11
Show Gist options
  • Save dwlamb/85f0af9357a2fd22bab1e48c71b7dca3 to your computer and use it in GitHub Desktop.
Save dwlamb/85f0af9357a2fd22bab1e48c71b7dca3 to your computer and use it in GitHub Desktop.
Making tmux command-prompt more intuitive
bind B command-prompt -pbuffer 'pasteb -b "%%"'
@dwlamb
Copy link
Author

dwlamb commented Jul 27, 2023

In this Stack Overflow article unix - tmux: Bind key to open command prompt with predefined command Nicholas Marriott provided the above syntax to add to a tmux.conf.

See the article for the Original Poster's question. Essentially, the use of this shortcut is to paste from a specific known buffer other than the most recent buffer.

Pressing C-b B one is presented with a prompt to enter the name of a buffer to paste from in the form bufferX X = a number in the buffer list.

The intent of the shortcut is to easily paste from a known specified buffer number other than the last item in the buffer list [ C-b ] ].

Without the shortcut, the conventional tmux method is the interactive list to choose a buffer to paste from. Press C-b = and an interactive screen opens displaying all the buffers used in tmux so far. Type a number corresponding to the left most column. That entry is pasted to the command prompt. In total the keystrokes are 4 C-b = 0, for example.

On its own, the above shortcut is inefficient for it is necessary to type bufferX. That is 7 keystrokes plus Enter.

My solution:

bind B command-prompt -pbuffer 'pasteb -b "buffer%%"'

Reloading tmux.conf and pressing C-b B one is presented with a prompt to enter the buffer number only, plus Enter. E.g., C-b B 0 Enter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment