How to copy text from one pane – MacOS/Tmux/Alacritty
Tags: learning, tmux, vim, dev
Published: 2023-05-03 18:13:49

---
title: How to copy text from one pane – MacOS/Tmux/Alacritty
published: true
date: 2023-05-03 17:54:19 UTC
tags: Learning,tmux,vim,dev
canonical_url: https://christine-seeman.com/2023/05/how-to-copy-text-from-one-pane-macos-tmux-alacritty/
cover_image: https://i.ibb.co/m5MYkVb/Screen-Shot-2023-05-03-at-1-05-37-PM.png
---

* * *

My problem? I only want to copy text from one tmux pane, not across two.

But I was finding that my mouse was failing me, and I knew there had to be a better way than just closing out my panes and only having one open. My journey on [understanding terminals, shells, editors,](https://christine-seeman.com/2021/04/lets-explore-what-is-a-shell-and-terminal/) and how to use them correctly has been rocky, but I have been feeling in a good place lately. The current setup that I am using is bash shell (starship shell prompt for that added sparkle), [Alacritty terminal](https://github.com/alacritty/alacritty), [Neovim editor](https://neovim.io/), and [Tmux](https://github.com/tmux/tmux/wiki) for running multiple terminals. I had gotten this all configured, which probably took too much time. Debugging your developer setup is a considerable learning experience, but developers (meaning me) sometimes (all the time) make it more complicated than it needs to be. I probably didn’t need to throw in attempting to theme everything too, but I like my consistent look.

![](https://i.kym-cdn.com/photos/images/newsfeed/001/018/871/d19.gif)

In my search to figure out how to copy the text on one pane, some [Linux](https://dev.to/sophiabrandt/copy-and-paste-in-tmux-494a-temp-slug-1778453) [solutions](https://www.rushiagr.com/blog/2016/06/16/everything-you-need-to-know-about-tmux-copy-pasting-ubuntu/) were close to what I needed but not 100% the way there. This setup got me all the way there with a solution that should fit nicely in my vim workflow.

The suggested Linux setup is a good start but does not work great for MacOS

```
 bind-key -T copy-mode-vi v send-keys -X begin-selection
 bind-key -T copy-mode-vi y send-keys -X copy-selection
 bind-key -T copy-mode-vi r send-keys -X rectangle-toggle

```

For MacOS, add the following onto your tmux configuration (for ex. at ~/.tmux.conf). This solution came from a [superuser post](https://superuser.com/a/1743290) from user [jeremysprofile](https://superuser.com/users/809706/jeremysprofile).

```
setw -g mode-keys vi
set -g set-clipboard off
bind-key -T copy-mode-vi v send-keys -X begin-selection
# bind y key in copy mode to select and copy to system clipboard
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"

```

The configuration will add some vi key bindings, and then to supercharge tmux copy mode. For copying and pasting, reach for typical vim keybindings. Start with `v` to select the text, then `y` to copy/yank the text. Then the text is in your copy buffer and ready for pasting.

Let’s see our new bindings in action.

Hit your terminal, start up `tmux` ( **`tmux source ~/.tmux.conf`** ) and make sure to refresh your config if you already have tmux open.

![](https://i.ibb.co/3RhGS9M/tmux-copy-1.png)

Split your pane (tmux default keys `C-b "`)

![Untitled](https://i.ibb.co/gt503kx/tmux-copy-2.png)

Load up some text on either side. I am looking at two readme files, one that I loaded up in vim and one that is just `cat` on the terminal.

![Untitled](https://i.ibb.co/qnCVPyC/tmux-copy-3.png)

Now attempt to use your mouse to highlight some text. You will notice that both sides will highlight.

![Untitled](https://i.ibb.co/C9snW1Y/tmux-copy-4.png)

Frustrating if you want the output from just the right side! Let’s use the new keybindings we added to the tmux configuration instead.

Switch over to tmux scroll mode (`C-b [`), use your arrow keys to move around, and when you are on the text that you want to copy, use `v` to make your selection.

![Untitled](https://i.ibb.co/vd1FzWY/tmux-copy-5.png)

What’s this? Only text selected on one side? Perfect! Copy the text using `y` , and it is ready to put where you need it. In my case, moving to my left pane (`C-b` then left arrow ), and then pasted (vim `p`) into my other readme.

![Untitled](https://i.ibb.co/k1qk93Q/tmux-copy-6.png)

Now we have a reusable, memorable solution for grabbing text in a single tmux pane!