Alternative/Remap `fn` key in OSX Terminal.app for `tmux`

1.4k Views Asked by At

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!

1

There are 1 best solutions below

0
On

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