3

I use tmux within macOS Sierra Terminal.app. When I want to disable Allow mouse reporting temporarily to copy/paste and clicking I need to press the fn key which is far away in my long apple keyboard. Is there a way to change this fn key to a closer key like ctrl, alt, option? I could not seem to find how after googling for a while.

Thanks!

  • Why are you disabling mouse reporting (Cmd-r for me) to copy and paste? Tmux has copy paste buffers, and macOS has pbcopy/pbpaste commands. This has nothing to do with vim, through from vim the `*` register should work, or you can write lines to `!pbcopy` and read lines from `!pbpaste` – D. Ben Knoble Jul 17 '19 at 13:13
  • when you are in tmux with mouse reporting you use tmux mouse selection but you cannot copy with cmd+c for instance (it is visual selection i think). if you hold fn key while mouse select then you are able to cmd + c. thats my point here. – Gabriel Borges Oliveira Jul 18 '19 at 07:52
  • Tmux uses `prefix-[` and `prefix-]` for copy and paste. No you cant use cmd-c, but you can feed the copied text to vim or to `pbcopy` (which is the same as using cmd-c). And you can hit cmd-r ro disable mouse if you absolutely must. Ill try to write up an answer describing my workflow when i get time. – D. Ben Knoble Jul 18 '19 at 12:36

1 Answers1

5

To toggle mouse reporting, press -R in Terminal.app.


I would like to share my Terminal.app + tmux + vim workflow as it relates to copy-paste, to suggest an alternative.

Vim to system

With vim from homebrew or +clipboard support, I make use of the "* register for yanks and puts. This interfaces well with the rest of the system.

You can always :r !pbpaste or :w !pbcopy too (described below).

Shell to system

macOS provides pbcopy(1) and pbpaste(1). By default they use the system clipboard. pbcopy is a sink that reads from stdin, while pbpaste is source that writes to stdout.

I use these regularly for command-line clipboard interactivity.

Tmux copy & paste

Enter copy-mode with the tmux copy-mode command (Prefix-[ by default).

Navigate with a series of keybindings.

Depending on EDITOR or VISUAL containing vi, tmux uses copy-mode with emacs-style bindings or copy-mode-vi with vi-like bindings—you can change the default in your .tmux.conf with the status-keys and mode-keys options. See man tmux for more details.

The default vi-like bindings are a bit lacking, in my opinion, so I opted to put the following in my .tmux.conf:

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

Once I've made a selection, I can put it anywhere in tmux with Prefix-]. There are buffers to choose from as well.

Tmux & vim

I can paste in vim via :set paste, o, and my tmux paste key. I use unimpaired, so paste toggling becomes ]op. With Tim Pope's tbone from github, I can also use :Tput and :Tyank in vim.

Tmux and system

Update: I've recently learned that the following will do the trick!

tmux show-buffer | pbcopy

This is the hardest piece: I usually do the following at a shell:

# pbcopy <<<'{TMUX PASTE}'

It's not perfect: if I paste anything with single quotes, I usually have to go through and do some editing work. In bash with readline in vi-mode, this as simple as <Esc>kv and then I can edit in vim until I'm satisfied.

A simpler and less error-prone alternative is often

# pbcopy
{TMUX PASTE}
<C-d> # send End-of-file
D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38