Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ ElementInclude
elementpath
ElementSoup
elif
emacs
emminent
Én
enabledrules
Expand Down Expand Up @@ -1024,6 +1025,7 @@ nc
ne
Nederlandse
neilb
Neovim
netcat
netnewswire
newData
Expand Down Expand Up @@ -1097,6 +1099,7 @@ ora
oraclespin
os
osascript
OSC
osem
osx
OSX
Expand Down Expand Up @@ -1475,6 +1478,7 @@ tmp
tmTheme
tmux
Tmux
tmux's
tmuxinator
tnsnames
tnsnamesora
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@
- [Using light and dark themes](ghostty/using_light_and_dark_themes.md)
- [Use Ghostty](ghostty/use_ghostty.md)
- [Visual config editor for Ghostty](ghostty/visual_config_editor.md)
- [Splits and tabs not in intended directory](ghostty/splits_and_tabs_not_in_intended_directory.md)
- [Copy on select](ghostty/copy_on_select.md)

<a id="git"></a>
### Git - version control system
Expand Down Expand Up @@ -1236,6 +1238,8 @@
- [Tmux Cheat Sheet & Quick Reference](tmux/cheatsheet.md)
- [Use sesh](tmux/use_sesh.md)
- [Use tmux-kiosk](tmux/tmux_kiosk.md)
- [Disable copy on mouse drag](tmux/disable_mouse_copy.md)
- [Copy on select in Ghostty with tmux](ghostty/copy_on_select.md)

<a id="tokei"></a>
### tokei - language statistics - fast
Expand Down
67 changes: 67 additions & 0 deletions ghostty/copy_on_select.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copy on Select

On **macOS**, selecting text in Ghostty does _not_ copy it to the clipboard by default. You have to press `cmd+c`, or turn on `copy-on-select`.

Check what your Ghostty is actually using:

```bash
ghostty +show-config --default | grep copy-on-select
```

```text
copy-on-select = none
```

The default is `primary` on Linux and `none` on everything else, macOS included.

## Enabling it

Add this to your Ghostty configuration, for example `~/.config/ghostty/config`:

```text
copy-on-select = clipboard
```

Then reload the configuration with `cmd+shift+,` or restart Ghostty, and validate it:

```bash
ghostty +validate-config
ghostty +show-config | grep copy-on-select
```

## The values

Ghostty 1.4.0 made the setting more than a boolean:

| Value | Linux | macOS |
| ----------- | --------------------------- | ---------------- |
| `none` | no copy | no copy |
| `primary` | selection clipboard | no effect |
| `clipboard` | system clipboard | system clipboard |
| `both` | selection + system | system clipboard |
| `true` | same as `primary` | same as `clipboard` |
| `false` | same as `none` | same as `none` |

Use `clipboard` on macOS. It says what it does, and it doesn't rely on what `true` happens to mean on the platform.

## When it seems to work only sometimes

If selecting text _sometimes_ copies and sometimes doesn't, check whether you are inside a terminal multiplexer like **tmux**. With `set -g mouse on`, tmux takes the mouse away from Ghostty, so any copying you see is done by tmux, not Ghostty.

Hold **Shift** while dragging to go around tmux (or any program that has taken the mouse, like vim or Claude Code) and use Ghostty's own selection. With `copy-on-select = clipboard` that copies every time. This depends on `mouse-shift-capture = false`, which is the default.

Shift+drag selects what is on the screen, so with side-by-side tmux panes it grabs text from both. Zoom the pane first with `prefix+z`.

See [Disable copy on mouse drag in tmux](../tmux/disable_mouse_copy.md) for the tmux side.

## Related settings

- `clipboard-trim-trailing-spaces` - trims trailing spaces from what is copied (default `true`)
- `clipboard-write` - whether programs may write to the clipboard using OSC 52 (default `allow`)
- `clipboard-read` - whether programs may read the clipboard (default `ask`)

## Resources and References

- [Ghostty Documentation: Configuration reference, copy-on-select](https://ghostty.org/docs/config/reference#copy-on-select)
- [Ghostty Documentation: Configuration](https://ghostty.org/docs/config)
- [Disable copy on mouse drag in tmux](../tmux/disable_mouse_copy.md)
134 changes: 134 additions & 0 deletions tmux/disable_mouse_copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Disable Copy on Mouse Drag

With `set -g mouse on`, tmux handles mouse selection itself. A drag selects text and, depending on your configuration, copies it to the system clipboard. This can get in the way of the terminal's own copy on select, for example [Ghostty's](../ghostty/copy_on_select.md), and can overwrite your clipboard when you didn't mean to copy.

## Where the copying comes from

tmux copies in two ways:

1. **Mouse drag** - when the drag ends, `MouseDragEnd1Pane` in copy mode runs a copy command. A common binding pipes the selection to `pbcopy` on macOS:

```tmux
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
```

2. **Double-click and triple-click** - the default bindings select a word or a line and run `copy-pipe-and-cancel`. With `set-clipboard` on, tmux sends that to the outer terminal using OSC 52, and it ends up on the system clipboard.

List the active bindings:

```bash
tmux list-keys | grep -E 'MouseDragEnd1Pane|DoubleClick1Pane|TripleClick1Pane'
tmux show -s set-clipboard
```

## Disabling it

Add this to your tmux configuration, after anything that sets up the bindings:

```tmux
unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode-vi MouseDragEnd1Pane
set -g set-clipboard off
```

Reload the configuration:

```bash
tmux source-file ~/.tmux.conf
```

Now:

- A **plain drag** still highlights text in the pane, but copies nothing. tmux stays in copy mode, press `q` or `Escape` to leave it
- **Double-click and triple-click** copy into tmux's own paste buffer only (paste with `prefix+]`)
- **Shift+drag** goes around tmux and uses the terminal's own selection

## The trade-off with set-clipboard

`set-clipboard off` blocks _all_ OSC 52 clipboard writes, including those from programs running inside tmux, like Neovim over SSH or the copy command in some CLI tools.

tmux has three values and none of them blocks tmux's own copies while letting programs through:

- `on` - both tmux and programs inside tmux can set the clipboard
- `external` - only tmux's own copy commands set the clipboard
- `off` - nothing sets the clipboard

If you need programs to keep that ability, leave `set-clipboard on` and rebind double-click and triple-click so they only select. They are bound in three key tables, and all three copy:

- `copy-mode` - copy mode with emacs keys (the default `mode-keys`)
- `copy-mode-vi` - copy mode with vi keys
- `root` - a normal pane, not in copy mode. This is where most double-clicks land

The defaults are the same commands with `run-shell -d 0.3 ; send-keys -X copy-pipe-and-cancel` at the end. Drop that part:

```tmux
set -g set-clipboard on

unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode-vi MouseDragEnd1Pane

bind -T copy-mode DoubleClick1Pane select-pane \; send-keys -X select-word
bind -T copy-mode-vi DoubleClick1Pane select-pane \; send-keys -X select-word
bind -T copy-mode TripleClick1Pane select-pane \; send-keys -X select-line
bind -T copy-mode-vi TripleClick1Pane select-pane \; send-keys -X select-line

bind -n DoubleClick1Pane select-pane -t = \; if -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { send-keys -M } { copy-mode -H ; send-keys -X select-word }
bind -n TripleClick1Pane select-pane -t = \; if -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { send-keys -M } { copy-mode -H ; send-keys -X select-line }
```

Check your own defaults first with `tmux list-keys | grep Click1Pane`, they can differ between tmux versions. The `if -F` part passes the click on to programs that have taken the mouse, like vim.

## Testing it

Test in a separate tmux server, so your running sessions are not affected. Run it from a terminal tab that is _not_ already inside tmux, otherwise the outer tmux gets the mouse first:

```bash
tmux -L copytest -f /path/to/test.conf new-session -s copytest
```

For each mouse action, put a known value on the clipboard, do the action, and see whether it changed:

```bash
printf %s "marker" | pbcopy
# double-click, triple-click or drag in the pane, then:
pbpaste
```

To check that programs can still write the clipboard, send an OSC 52 sequence from inside the pane:

```bash
printf '\e]52;c;%s\a' "$(printf osc52-ok | base64)"
pbpaste
```

With the bindings above, on tmux 3.8 in Ghostty:

| Action | Result |
| ----------------------- | -------------------------------- |
| Double-click | clipboard unchanged |
| Triple-click | clipboard unchanged |
| Plain drag | clipboard unchanged |
| OSC 52 from a program | clipboard set |
| Shift+drag | clipboard set by the terminal |

Shift+drag only copies if the terminal copies on select itself. A running Ghostty does not pick up configuration changes on its own, so reload it with `cmd+shift+,` first.

Remove the test server afterwards:

```bash
tmux -L copytest kill-server
```

## The alternative: mouse off

`set -g mouse off` gives the mouse back to the terminal completely, so every plain drag uses the terminal's own selection. You lose mouse wheel scrolling through tmux history, clicking to focus a pane, and dragging pane borders to resize.

## A note on generated configuration

If part of your tmux configuration is written by a tool (an installer, a plugin or a session manager), put your overrides in a file you own that is sourced _after_ it. Otherwise the next update to that tool may overwrite them.

## Resources and References

- [tmux manual page](https://man.openbsd.org/tmux)
- [tmux Wiki: Clipboard](https://github.com/tmux/tmux/wiki/Clipboard)
- [Copy on Select in Ghostty](../ghostty/copy_on_select.md)