Ghostty + tmux uniform copy and paste
This set of configuration changes achieves the following:
- Disable automatic copying to clipboard while using the mouse to select text. Instead, the selection is copied when the user types either Ctrl+Shift+c or Super+c (on macOS only) after using the mouse to select text.
- The Super+c keybinding works by remapping it to Ctrl+Shift+c in ghostty.
- Ghostty will ignore those keybindings so that tmux can handle them. This allows tmux to copy text cleanly even when scrolling through history and using split panes.
- Ghostty will still handle pasting with Ctrl+Shift+v or Super+v (on macOS only).
- The r key can be pressed while selecting text to toggle rectangular selection on or off.
- Clicking outside the selection will clear the selection.
- The selection will be displayed as inverse text on both tmux and ghostty for consistency.
Files
ghostty-mac.conf
Apply these changes to ~/.config/ghostty/ghostty.conf if you’re on macOS:
copy-on-select = false
keybind = performable:ctrl+shift+c=copy_to_clipboard
# remap super+c to ctrl+shift+c, use `bash -i -c cat` to see keycodes
# as you type them
keybind = super+c=csi:99;6u
selection-invert-fg-bg = true
shell-integration-features = no-cursor
ghostty-linux.conf
Apply these changes to ~/.config/ghostty/ghostty.conf if you’re on Linux:
copy-on-select = false
keybind = performable:ctrl+shift+c=copy_to_clipboard
selection-invert-fg-bg = true
shell-integration-features = no-cursor
tmux.conf.local
Add these changes to ~/.tmux.conf.local, assuming that you’re using
oh-my-tmux↗:
# increase history size
set -g history-limit 10000
# start with mouse mode enabled
set -g mouse on
# don't yank mouse selection on release; instead use alt+w
# or ctrl+shift+c
unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode MouseDown1Pane
bind-key -T root DoubleClick1Pane select-pane -t = \; \
if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { \
send-keys -M \
} { \
copy-mode -H ; \
send-keys -X select-word \
}
bind-key -T root TripleClick1Pane select-pane -t = \; \
if-shell -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { \
send-keys -M \
} { \
copy-mode -H ; \
send-keys -X select-line \
}
bind -T copy-mode MouseDown1Pane select-pane \; send-keys -X clear-selection
bind -T copy-mode DoubleClick1Pane select-pane \; send-keys -X select-word
bind -T copy-mode TripleClick1Pane select-pane \; send-keys -X select-line
bind -T copy-mode C-S-c send-keys -X copy-pipe
bind -T copy-mode R send-keys -X refresh-from-pane
bind -T copy-mode r send-keys -X rectangle-toggle
# selection style
setw -g mode-style "reverse" #!important
Note that the location of .tmux.conf.local might be different depending on how
you’ve configured oh-my-tmux.