Tmux Part 3: Navigation

@captain_zoom Did you figure this out yet? I have the same issue except <C-h> works in non-vim contexts but fails to work in vim itself (using urxvt, bash and neovim)

This is a neovim bug, and known issue <C-h> (CTRL-H) does not work in the new TUI Ā· Issue #2048 Ā· neovim/neovim Ā· GitHub
It works just fine in regular vim, which sucks because nvim is my day to day.

Adding this to your init.vim will make the plugin work

if has('nvim')
  nmap <BS> <C-w>h
endif

My prefix is C-Space and common shortcuts I use for navigating sessions and windows is <Prefix>-w which allows you to choose from the windows you have open.
Another is <Prefix>-s for navigating the sessions I have running.
Pane navigation I do using Ctrl-(h,j,k,l).

Hey Guys so for us non-OS users to copy and paste I used the Tmux-yank plugin located here: GitHub - tmux-plugins/tmux-yank: Tmux plugin for copying to system clipboard. Works on OSX, Linux and Cygwin.

Works the same or even better than the one Chris uses. Read the docs for it.

This is seriously the life saver I was looking forā€¦ Hearted and bookmarked and gisted :slight_smile:

I use lxterminal with tmux, and am able to use the vim style copy and navigation in copy mode. But in order to paste to command line, I had to use <prefix> ]. Is there a better way to paste? Thanks.

This is an EXCELLENT workflow course. I have a quick question though - was there some trick involved in making J and K work in ā€˜choose-treeā€™? the man pages specifics only the arrow keys can be used.

@amitz Thanks for the kind words! Youā€™ll need to set vi key bindings in tmux to make J and K work:

# in your ~/.tmux.conf
setw -g mode-keys vi

@christoomey oh, Iā€™m sorry. I didnā€™t use the above copy/paste snippet as I mostly use mouse highlighting to copy from the terminal to the clipboard (I know, shame on me :-)). Thanks for clearing it up!

Yes, lifechanging :slight_smile:

It ought to be stated that:

bind-key - split-window -v -c '#{pane_current_path}'
bind-key \ split-window -h -c '#{pane_current_path}'

ā€¦requires tmux v1.9 or greater.

If you are using tmux 2.4 or later, the instructions for enabling copy and paste on OS X will not work. These lines seem to be the 2.4 compatible equivalent of the suggested configuration:

# Use vim keybindings in copy mode
setw -g mode-keys vi

# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

References: tmux 2.4 changelog and the man page section ā€œWindows and panesā€.

1 Like

@amitz And how do you get mouse highlighting to work? I have to use
<Option><Command>
It works, but is really awkward.

@JESii Iā€™m using urxvt terminal for that with xlip (Iā€™m a Linux user). Hereā€™s how the Tmux configuration looks like:

# Allowing you to copy on highlight into the primary clipboard
set -g mouse on
bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "xclip -selection clipboard"
bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "xclip -selection clipboard"
1 Like

Thanks, @amitzā€¦ That should be doable on OS X ā€“ Iā€™ll give that a whirl!

OMG - with a little tweak for tmux 2.5 (Iā€™m running on HEAD from brew) that worked ā€“ something Iā€™ve been struggling with for quite some time.

First, thereā€™s a breaking change in later versions of tmux (starting with 2.4, I believe): a ā€œFundamental change to how copy mode key bindings workā€ is described here.

In short, vi-copy (and emacs-copy) tables are ā€œgoneā€ and now referenced simply as ā€˜copy-modeā€™. Also the bind -t xxx becomes bind -T xxx. Not sure exactly how that works as my existing bind -t vi-copy xxx commands are not causing errors? So your command be becomes
bind-key -T copymode MouseDragEnd1Pane copy-pipe "reattach-to-user-namespace pbcopy"
on my system.

For a moment I thought it was broken until I realized that the selection goes immediately into the clipboard, without to follow the selection with <Cmd-v> to copy the selection: as soon as you let go of the mouse ā€“ poof ā€“ itā€™s there in the clipboard.

Awesome ā€“ thanks so much for the comment; really made my day (week? month?) :smile:

UPDATE - YMMV: This stuff seems to be changing quite a bit (or Iā€™m copy/paste-challenged:). The above command worked on my personal system (compiled/installed from tmux master in Jan/2017 on either V2.3 or V2.4). When I ported the command to my Client system (home brew HEAD version just updated), it didnā€™t work and I had to change it to:
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe "reattach-to-user-namespace pbcopy"
Notice the copy-mode-vi and send -X changes. I plan to port this back to my personal system and see if this one works both places.

Lifesaver. I started going done the rabbit hole to update the config file and find this. Many thanks.

@christoomey, you all may want to flag this note in the Copy and Paste section with this update for people who are running tmux >= v2.4.

@gbonfant your fish function is so awesome! Thank you :slight_smile:

Iā€™ve tried every possible combination of commands and I still canā€™t get any of the copy mode stuff to work.

Hereā€™s how I replaced the vi-copy lines, based on the responses in this issue from the tmux repo:

# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'

# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"

Also, Iā€™m using iTerm and had to enable clipboard access in Preferences > General > ā€œApplications in terminal may access clipboardā€.

I had the same issue, and didnā€™t want to disable OSX shortcuts. So, I switched to using C-S-<Left | Right | Down | Up> instead.

It works for me right now, but Iā€™m not sure if the Ctrl-Shift-ArrowKeys keybindings will be needed for something else in the future.

If anyone else is having issues with the vertical split shortcut and is running tmux 3.0 or higher you need to escape the backslash because theyā€™ve changed parsing libraries.

bind-key \\ split-window -h -c '#{pane_current_path}'