tmux/Q/In copy mode with vi keys, can you drop a selection without leaving copy mode?
In tmux copy mode with vi keys, can you drop a selection without leaving copy mode?
Answer
- AI/Response
- Yes, tmux can do this with the copy-mode command
clear-selection, which removes the highlight without leaving copy mode, so your scroll position stays put. Why
vdoes not “toggle off” like Vim- In typical oh-my-tmux-style vi copy-mode tables,
vis bound tobegin-selection, not to “exit visual.” Pressing **vagain usually starts or resets selection behavior rather than acting like Vim’s visual toggle—so your observation is expected. C-vis oftenrectangle-togglein the default vi table (orthogonal to “exit visual”).
- In typical oh-my-tmux-style vi copy-mode tables,
Why Escape may kick you out entirely
- Many configs (including common oh-my-tmux patterns) bind
Escapeincopy-mode-vitocancel, which exits copy mode—the opposite of “only clear the selection.” That matchestmux list-keys -T copy-mode-vion typical setups. Stock documentation sometimes describesEscapeas “clear selection” in older tables or mixed emacs/vi docs; trusttmux list-keys -T copy-mode-vifor your session.
- Many configs (including common oh-my-tmux patterns) bind
What to use instead
- Bind
clear-selectionto a key you can reach in copy mode, for exampleC-g(mnemonic: cancel selection, not the whole mode): - text
bind-key -T copy-mode-vi C-g send-keys -X clear-selection - Or make
Escapeconditional so it clears when something is selected and only cancels when there is no selection (pattern discussed in community answers and blog posts): - text
bind-key -T copy-mode-vi Escape if-shell -F "#{selection_present}" "send-keys -X clear-selection" "send-keys -X cancel" - After adding bindings, reload config (
tmux source-file ~/.tmux.conf) or restart tmux.
- Bind
Verify your table
Sources
- tmux(1) — OpenBSD man page (copy-mode /
send-keys -Xcommands) - How to stop marking while in tmux copy-mode? (Unix & Linux SE)
- Selecting text in Tmux copy mode (Super User) (historical key tables; cross-check with
list-keys)
- tmux(1) — OpenBSD man page (copy-mode /
- Yes, tmux can do this with the copy-mode command
- AI/Response