Skip to content

Commit

Permalink
Tmux: Update tmux 2.4 compatibility (copy-mode-vi)
Browse files Browse the repository at this point in the history
The new version of tmux (2.4) again includes a breaking change
in which 'bind-key -t vi-copy' has been removed and replaced by
'bind -T copy-mode-vi'.

This commit makes the 'v' and 'p' commands (under the copy mode)
work again; the configuration is compatible with both tmux 2.3
and 2.4.
  • Loading branch information
wookayin committed May 24, 2017
1 parent bfb0037 commit 3e255e9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tmux/tmux.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# tmux.conf
# for tmux 2.1+ : mainly for tmux 2.3 (highly recommended)
# for tmux 2.1+ : mainly for tmux 2.3 and 2.4 (highly recommended)
#
# @seealso
# - http://manpages.ubuntu.com/manpages/precise/man1/tmux.1.html


# Set the TMUX_VERSION envvar (up to minor versions)
# https://stackoverflow.com/a/40902312/1046584
run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-)"


# 1. Key Bindings {{{
# ===================

Expand Down Expand Up @@ -114,8 +119,18 @@ bind-key Escape copy-mode
bind-key Enter copy-mode
bind-key ] paste-buffer

bind-key -t vi-copy 'v' begin-selection # Begin visual-selection in copy mode.
bind-key -t vi-copy 'y' copy-pipe "pbcopy" # Yank the current selection in copy mode.
# vi-mode v: Begin visual-selection in copy mode.
# vi-mode y: Yank the current selection in copy mode.
if-shell -b '[ "$(echo "$TMUX_VERSION <= 2.3" | bc)" = 1 ]' \
'bind-key -t vi-copy "v" begin-selection; \
bind-key -t vi-copy "y" copy-pipe "pbcopy"; \
'
# see https://github.com/tmux/tmux/issues/754
if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.4" | bc)" = 1 ]' \
'bind -T copy-mode-vi "v" send-keys -X begin-selection; \
bind -T copy-mode-vi "y" send-keys -X copy-pipe "pbcopy"; \
'

bind-key 'p' run-shell "pbpaste | tmux load-buffer - && tmux paste-buffer"

# no delay when switching modes (copy mode, etc.)
Expand Down

1 comment on commit 3e255e9

@wookayin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related Issue: #5

Please sign in to comment.