tmux-plugins / tmux-copycat

A plugin that enhances tmux search
MIT License
1.11k stars 63 forks source link

Clobbers tmux bind of Ctrl+J #60

Closed unphased closed 9 years ago

unphased commented 9 years ago

When I activate the copycat command with Ctrl+A, /, subsequently the tmux bind made by me using bind -n C-J stops working. It appears that the plugin sets the bind to

bind-key -n       C-j run-shell "tmux send-keys 'C-j'; /root/.tmux/plugins/tmux-copycat/scripts/copycat_mode_quit.sh; true"

I wonder if there is a way for copycat to store the existing binding before overwriting it so that it can restore the original bind when done with copycat mode?

bruno- commented 9 years ago

Hey, we've had this issue reported in #53. I also propose steps how to fix this in that issue:

unbind C-j so that it no longer exits copy mode. This is the line to put in tmux.conf: unbind -t vi-copy C-j

Can you please confirm this fixed the issue for you?

unphased commented 9 years ago

(I am trying this now that i this breakage has finally gotten on my nerves to a sufficient degree. You see, I use the Ctrl+HJKL keys to do tmux pane directional navigation, and i am a heavy Vim user.)

Now I have one question -- it's not clear to me what the vi-copy key binding has to do with affecting the regular -n C-J binding. You say that the fix is to put the line that unbinds C-j for the vi-copy mode into my tmux config, but surely this will fail if I insert the line before the place where my tmux plugins are specified and presumably initialized?

Of course I am physically capable of inserting this line at the bottom, then it no longer is the case (as tpm's instructions are clear to state) that tpm's initialization remains at the bottom of my tmux configuration.

Then again I am just being overly pedantic to the point of being a joke, and I'll be sure to close this once I verify that it solves my problem. Thanks.

unphased commented 9 years ago

Yup I tested and it works. However I did also test the case where I paste unbind -t vi-copy C-j into my .tmux.conf but only at the top and it still works to suppress the C-J bind. This has me confused, but not enough to actually dig into it to figure out why it still works.

bruno- commented 9 years ago

Thank you for confirming this works. I should probably put some effort into fixing this properly so other users don't have to deal with this.

Now I have one question -- it's not clear to me what the vi-copy key binding has to do with affecting the regular -n C-J binding

tmux-copycat defines a set of -n bindings to create "copycat mode". Examples are n and N keys to jump to next/previous match. This couldn't be done with "vi-copy" or "emacs-copy" key bindings. There's no way for those key bindings to execute shell scripts (I asked tmux creator).

The -n key bindings are undefined and reset to default when a users exits "copycat mode". We need to know which keys can exit tmux's copy mode and override them to detect this and reset -n bindings to defaults.

Some of the keys that can exit copy mode by default are ctrl-c, enter, q and ctrl-j. We're "dynamically" fetching a list of those keys (see this function) and overriding it with -n mappings.

If that function does not return C-j as the key that exits copy mode, it is never overridden with -n mapping.

I paste unbind -t vi-copy C-j` into my .tmux.conf but only at the top and it still works to suppress the C-J bind

It doesn't matter where you undefine C-j (top or bottom of tmux.conf). Previously linked function runs at the moment a user invokes "copycat mode" (for example with a stored search). It is at that moment that the ctrl-c, enter, q and ctrl-j keys are dynamically overridden.

This is pretty complex. Let me know if you want more details about any of this.

mMontu commented 9 years ago

I had the exactly same problem, while using C-j for pane navigation.

The command unbind -t vi-copy C-j indeed solved the problem. Maybe it could be included as part of the plugin, saving time for other users ( avoiding understanding when/why the key is unbinded and searching for this fix).