christoomey/vim-tmux-navigator

Failed to bindkey in tmux 3.0 `tmux 3.0: bindkey c-\`

l-qing opened this issue · 9 comments

Hello, great plugin, love it.

REFERENCE: tmux/tmux#1827

The following is a configuration line that is working well on tmux <= 2.9:

bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

In 3.0, it fails to parse near :

.tmux.conf:250: unknown key: C- if-shell

Try this:

bind -n 'C-\' if-shell "$is_vim" "send-keys 'C-\\'" "select-pane -l"

solution:

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
bind-key -n 'C-\' if-shell "$is_vim" 'send-keys C-\\' 'select-pane -l'
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

Can you update the README.md?

Cutting edge! Thanks for sharing the update. I'm wondering, is the new version that you shared backward compatible?

Cutting edge! Thanks for sharing the update. I'm wondering, is the new version that you shared backward compatible?

Thanks for your reminder.

I tried it in tmux 2.6, most of them are compatible.
But, only one issue: in vim, Ctrl-\ not work, it insert the -\\

So, I modified it.
Now, it's backward compatible.

The latest script is as follows

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
if-shell '[ $(echo "$(tmux -V | cut -d" " -f2 | tr -d "[:alpha:]") < 3.0" | bc) -eq 1  ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell '[ $(echo "$(tmux -V | cut -d" " -f2 | tr -d "[:alpha:]") >= 3.0" | bc) -eq 1  ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

Maybe the config in the README should be updated to this backward compatible version

I'm having trouble getting ctrl-\ working on tmux 3.0a.

This snippet works on 3.0a (where "works" means ctrl-\ toggles between panes in both vim panes and regular panes)

bind -n 'C-\' if-shell "$is_vim" "send-keys C-\\\\" "select-pane -l"

This works on 2.4

bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

But this snippet (taken from the README) doesn't work on 2.4, in the sense that ctrl-\ doesn't do anything. No error messages either on loading the conf file or when you press ctrl-, but nothing happens either.

tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

Any ideas?

I'm having trouble getting ctrl-\ working on tmux 3.0a.

This snippet works on 3.0a (where "works" means ctrl-\ toggles between panes in both vim panes and regular panes)

bind -n 'C-\' if-shell "$is_vim" "send-keys C-\\\\" "select-pane -l"

This works on 2.4

bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

But this snippet (taken from the README) doesn't work on 2.4, in the sense that ctrl-\ doesn't do anything. No error messages either on loading the conf file or when you press ctrl-, but nothing happens either.

tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

Any ideas?

This can work for me.
You can try it.

if-shell '[ $(echo "$(tmux -V | cut -d" " -f2 | tr -d "[:alpha:]") < 3.0" | bc) -eq 1  ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell '[ $(echo "$(tmux -V | cut -d" " -f2 | tr -d "[:alpha:]") >= 3.0" | bc) -eq 1  ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"

Thanks. Same problem: ctrl-\ works inside vim, but not in a regular pane.

Thanks. Same problem: ctrl-\ works inside vim, but not in a regular pane.

Can you see the key mapping by Ctrl-b + ?
It can show the key Ctrl-\ mapping.
It’s has two mapping for each mode.
You can try to see the different by the each config of tmux.

If possible, update your tmux version .😂

I'm trying to construct a config that works for the multiple versions of tmux I see on various servers, so upgrading doesn't help unfortunately.

The leader (ctrl-s in my case) doesn't help (presumably because all these bind-key commands are issued with -n.

I think at this point I've run into a tmux issue (rather than vim-tmux-navigator), so I'll try and get help over there.

Thank you!

ctrl-\ is also not working for me when in vim in tmux 3.0a. It works fine in another pane, but it will not work from within a vim pane. I always see Syntax error in the tmux status bar.

If I manually insert send-keys C-\ into tmux, it also prints Syntax error. If I escape the slash and do send-keys C-\\, it works fine.

My config is this:
bind-key -n C-\\ if-shell "$is_vim" 'send-keys C-\\\\' "select-pane -l"

I have tried various combinations for escaping the backslashes in the send-keys bit, but nothing works. I've tried "send-keys C-\\", 'send-keys C-\', 'send-keys C-\\', "send-keys C-\\\\", 'send-keys C-\\\\', nothing seems to work.

EDIT: I updated all my tmux plugins and it seems to work now when using 'send-keys C-\'