← Back to Upcase

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 https://github.com/neovim/neovim/issues/2048
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: https://github.com/tmux-plugins/tmux-yank

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}'