Skip to content

Instantly share code, notes, and snippets.

@mwolson
Last active January 7, 2025 16:11
Show Gist options
  • Save mwolson/b079f5941d668c282448fa35e92c13fc to your computer and use it in GitHub Desktop.
Save mwolson/b079f5941d668c282448fa35e92c13fc to your computer and use it in GitHub Desktop.
Ghostty + tmux uniform copy and paste

Ghostty + tmux uniform copy and paste

Explanation

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.

Caveats

  • If you're using ghostty without tmux, the selection will no longer be copied.
  • The unconsumed: target currently doesn't work with Ctrl+Shift+c and Super+c; once it does, that might be a good way to address the above problem.

Files

ghostty-mac.conf

Apply these changes to your ~/.config/ghostty/ghostty.conf file if you're on macOS.

ghostty-linux.conf

Apply these changes to your ~/.config/ghostty/ghostty.conf file if you're on Linux.

tmux.conf.local

It's assumed that you've installed oh-my-tmux. The changes in this file can be added to your ~/.tmux.conf.local file - this location might be different depending on how you've installed oh-my-tmux.

copy-on-select = false
# doesn't currently work as of ghostty v1.0.1:
#keybind = unconsumed:ctrl+shift+c=copy_to_clipboard
keybind = ctrl+shift+c=unbind
selection-invert-fg-bg = true
shell-integration-features = no-cursor
copy-on-select = false
# doesn't currently work as of ghostty v1.0.1:
#keybind = unconsumed:ctrl+shift+c=copy_to_clipboard
keybind = ctrl+shift+c=unbind
# 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
# 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 M-w or C-S-c
unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode MouseDown1Pane
bind -T copy-mode MouseDown1Pane send-keys -X clear-selection
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment