tmux-plugins/tmux-copycat

Problems with Tmux 2.4

thalesmello opened this issue ยท 27 comments

Since tmux 2.4 (currently in development), the way vi key bindings for copy-mode and the dynamics for send-keys have changed.

Therefore, this plugin currently doesn't work.

In case there is anyone interested, I have a fork that I managed to make it work for copy-mode in vi key bindings (emacs would need a bit more of work).

I won't open a pull request as that would break compatibility with previous versions.

Thank you, this was driving me nuts! ๐Ÿ‘

@thalesmello U seems to be maintaining this plugin. Could you please take a look at my question? No one will respond to it here probably.

#111

Thanks!

Hi, I think I've been hit by this now, as well as any other ArchLinux user, please check tmux-plugins/tmux-yank#76. The plugin sadly simply stopped working.

@oblitum Thank you for pointing the issue with tmux-yank. I wasn't aware of it.

It wouldn't take much effort to adjust my fork to make it work with previous versions of Tmux.

I don't have time to do it now. I'll open a pull request as soon as I get a chance to.

@thalesmello thanks, I'm using your fork meanwhile.

@thalesmello I've figured out your patch is not working for me in the end:

  • with tmux-yank working (tmux-plugins/tmux-yank#76 applied)
  • check that simply select and yank is working fine (yank and paste something without using tmux-copycat)
  • now try prefix + ctrl-u or any, to select, or even not select anything at all
  • tmux-copycat selection will work
  • yank of such selection appears to work since selection vanishes
  • now tmux-yank is broken, when pasting I see it didn't yank the copycat selection, it is still with the original
  • I can't yank anything anymore, I have to reload .tmux.conf for tmux-yank to work again

@oblitum Here is why.

Copycat tries to figure out which keys exit copy mode in order to override the original hooks to clear up copycat specific keybindings when you exit copy mode. The problem is that it assumes that any keybinding that has the cancel keyword exits copy-mode.

All the while, the tmux-yank plugin registers keybindings using copypipe-and-cancel keybinding, which also exits copy mode.

So here is what happens:

  1. tmux-yank registers copypipe-and-cancel keybindings to copy text.
  2. tmux-copycat overrides these shortcuts with special hooks to clear up copycat keybindings when the user wants to leave copy mode. Note that this also overrides the original yank behavior.
  3. After tmux-copycat exists copy mode, it replaces the original keybindings by cancel shortcuts. And that's why tmux-yank stops working after that.

So, in order to solve this issue, copycat has to be smarter in order to know the original keybindings, all of that in order to be able to correctly exit copy mode and clear copycat's keybindings (without losing the yank capability) and also be able to restore the original keybindings.

That would be quite a bit more of work, which I didn't have to do because I simply use copypipe (without tmux-yank) and that doesn't conflict with copycat's keybindings.

I can try to take a look at it when I have time, but I have no idea when I will take a look at it.

In case you want to use by approach, the relevant keybindings are as follows:

bind-key -Tcopy-mode-vi y send -X copy-pipe "reattach-to-user-namespace pbcopy"\; send -X clear-selection
bind-key -Tcopy-mode-vi Enter send -X copy-pipe "reattach-to-user-namespace pbcopy"\; send -X clear-selection

I'm freezing to 2.3 for now... too many issues, all plugins (copycat, yank, open, ...?) suddenly stopped working because of the breaking change in 2.4.

@thalesmello Just a heads up that for me, your fork can select copycat results several characters too late (which can end up being on the next line etc). Some quick tests imply it's the Unicode characters in my prompt (from Powerline), as any lines that look like ASCII-only are fine. Thanks for the fork, though; partially working is heaps better than before.

bind-key -Tcopy-mode-vi Enter send -X copy-pipe "reattach-to-user-namespace pbcopy"\; send -X clear-selection

@thalesmello Do you know if it is possible to exit copy mode afterwards? I tried a few variations (like sending cancel after clear-selection) but then the text is not copied to the clipboard.

@davidjb Do you think you could provide for a way to reproduce this problem?

@laktak Yes, it is, but it requires changes to the code in my fork. Given the number of people in seeing this solved, I'll try to work on it this week.

How can I install tmux 2.3 from brew? I am getting 2.4 by default.

Never mind, built from source.. easier.

@AlexKvazos you can use brew switch too. even easier. brew switch tmux 2.3_3

@thalesmello, your fork seem very nice!

I guess it would be nice to keep compatibility with older versions, in a similar way as it as done on https://github.com/tmux-plugins/tmux-yank/pull/82/files

Hello @labianchin
I will do it eventually. I don't have the time right now.

@thalesmello thanks for your efforts; I cloned your repo today, but tried to run it but I see the following
relavent info: mac os x 10.12.5 ; fish shell 2.5.0 and the following config for tmux; https://gist.github.com/c9ab1c8a6bc5bcd5a1c69fc08f50e056

  1. File search doesn't seem to work ;
  2. When i do the simple \ search then try to yank a match via y or Enter it doesn't add it to my clipboard.

@arooni Are you using Vi or Emacs keybindings?

My fork is only configured to work with vim keybindings.

@thalesmello vi keybindings. Sorry if that wasn't clear.

szero commented

Hi, I'm using tmux 2.5 and I noticed that this plugin unbinds all your bindings that exit from copy mode (all that contain cancel keyword). I'm using this keybind bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "xsel -ib" to save copy mode selection into system clipboard selection. I wrote simple patch to prevent this behavior and I didn't notice any negative effects caused by it. I specified y and Y key there because they are the ones that are used in the tmux-yank plugin.

On ArchLinux now I can't freeze on tmux 2.3 anymore because dependencies (libevent) got newer, so I'm forced to upgrade to 2.4/2.5. Sadly then, the triad yank/copycat/open is still broken because copycat is still not fixed :(

Thanks to the hint of @thalesmello I could fix the issue of tmux-copycat breaking the tmux-yank functionality. I did that in yet another fork.

Hey @Sflip, thanks for the fix, it works almost well :) One issue I found:

  1. $ echo "one\ntwo" to have some text content in terminal
  2. Prefix, / to start search, type "one" and press Enter
  3. "one" was correctly found, now press Y to copy it in the prompt
  4. Now try to search "two" using the same sequence, Prefix, / to start search, type "two" and press Enter

Expected: you found "two"
Actual: the next occurrence of "one" is found, i.e. tmux keeps searching for "one", not for "two".

Closing this PR as it was addressed via #119