tmux-yank icon indicating copy to clipboard operation
tmux-yank copied to clipboard

prefix-y isn't working correctly

Open docwhat opened this issue 8 years ago • 19 comments

Several people have reported problems with prefix-y in tmux "normal" mode.

  1. @arooni
  2. @ltWolfik

docwhat avatar Jun 07 '17 05:06 docwhat

same with me 😭

  • macOS 10.12.5
  • zsh 5.3.1
  • tmux 2.5

xieyunzi avatar Jun 08 '17 08:06 xieyunzi

So this isn't a feature I've used before I took over this plugin. So I'd like help with understanding the user-story to see if I can figure it out.

The documentation I have says:

  • Normal Mode

  • prefixy — copies text from the command line to the clipboard.

    Works with all popular shells/repls. Tested with:

    • shells: bash, zsh (with bindkey -e), tcsh
    • repls: irb, pry, node, psql, python, php -a, coffee
    • remote shells: ssh, mosh
    • vim/neovim command line (requires vim-husk or vim-rsi plugin)

But I'm confused how it did/does this. Can anyone shed some light on it? The only way I can think of it is to try to grab the current cursor to the end of line, but that won't work in all cases. And the zsh (with bindkey -e) comment confuses me further.

docwhat avatar Jun 14 '17 03:06 docwhat

Hey, this feature is used to copy whatever the currently typed text on your command line (before you press enter). Say, this is my command line: > foo bar baz_ and the cursor is on the position of _. When I invoke this feature I should get foo bar baz in the system clipboard.

I just tried it on osx, tmux 2.5 and it worked ok.

The feature uses readline shell features. Here's roughly how it works (I'll write from memory, didn't check the latest code):

  • sends ctrl-a to the underlying shell which moves the cursor to the beginning of the line
  • enters tmux copy mode
  • starts a text selection
  • goes to the end of the line while in tmux copy mode (this action visually selects the whole content of the command line)
  • copies the selection to the system clipboard
  • exits tmux copy-mode

bruno- avatar Jun 14 '17 14:06 bruno-

I just checked the code. What I wrote above is pretty correct as it corresponds to the order of function calls in scripts/copy_line.sh

yank_current_line() {
    go_to_the_beginning_of_current_line
    add_sleep_for_remote_shells
    enter_tmux_copy_mode
    start_tmux_selection
    end_of_line_in_copy_mode
    yank_to_clipboard
    go_to_the_end_of_current_line
    display_message 'Line copied to clipboard!'
}

And the zsh (with bindkey -e) comment confuses me further

I never played with zsh but if I remember correctly the bindkey -e option enabled the above mentioned readline feature required for this plugin to work. By default when you type C-a in zsh it does nothing. With the above option the behavior will change so that cursor goes to the beginning of the command line.

vim-husk and vim-readline vim plugins enable the same behavior for vim's command line (Ctrl-a moves cursor to the beginning of the command line)

bruno- avatar Jun 14 '17 14:06 bruno-

I think I solved a similar problem by creating an alias to copy the last run command:

# .zshrc
alias copy-last-command='fc -l -n -1 -1 | tr -d "\n" | pbcopy'

docwhat avatar Jun 21 '17 18:06 docwhat

doesn't work for my also anymore :( maybe it has something to do with this update? https://shapeshed.com/custom-vim-bindings-in-tmux-2-4/

Seybo avatar Jul 08 '17 09:07 Seybo

@Seybo what tmux version do you have tmux -V? This feature should work on tmux 2.5 (I'm using it daily).

bruno- avatar Jul 08 '17 22:07 bruno-

@bruno I have tmux version 2.5 and your plugin stopped working exactly after I updated it. Also I use the oh-my-tmux config which you can find here. Interesting that it seems the only not working command is the copy selected text prefix-y. Prefix-Y and Shift-Y work fine. So then I put in my config unbind y, unbind C-y thinking of possible conflicting default binding for this key but fruitless. Then I tried to find a conflicting binding and found these lines in oh-my-tmux config which seem to use y, right? And I removed them and reloaded config but your plugin prefix-y command didn't start to work.

How can I rebind this only command? Is there a way to do that?

Seybo avatar Jul 09 '17 05:07 Seybo

@Seybo If you are using tmux-copycat together with this plugin, it won't work as intended. If you need copying to clipboard right now you may want to remove this plugin until its fixed and try my quickfix from here.

szero avatar Jul 09 '17 11:07 szero

@szero no I don't use copycat plugin here are my configs: base changes and additional stuff

Seybo avatar Jul 09 '17 12:07 Seybo

@Seybo does copying works for you when you uncomment this line and comment previous one?

szero avatar Jul 09 '17 14:07 szero

@Szero nope. I've already tried to comment all this block and it doesn't work either. But i've checked you suggestion now and no, no changes

Seybo avatar Jul 09 '17 14:07 Seybo

@Seybo how about moving this and this before bind-key declarations?

szero avatar Jul 09 '17 14:07 szero

@Szero no changes as well. I was experimenting with these two just because of this problem. So I don't need them. Thanks for pointing out on them :)

Seybo avatar Jul 09 '17 14:07 Seybo

NOT using set -g @shell_mode 'vi' solved this problem for me with tmux 2.2 on Fedora 25.

When this setting is present, using prefix-y seems to cause the terminal to enter a state that would result from pressing Alt+number (entering a character multiple times) for a split second. This indicates a potential problem with the underlying command sequence that is run by prefix-y - it looks like a keybinding conflict to me.

dzikkoder avatar Oct 04 '17 09:10 dzikkoder

The feature uses readline shell features. Here's roughly how it works (I'll write from memory, didn't check the latest code):

  • sends ctrl-a to the underlying shell which moves the cursor to the beginning of the line
  • enters tmux copy mode
  • starts a text selection
  • goes to the end of the line while in tmux copy mode (this action visually selects the whole content of the command line)
  • copies the selection to the system clipboard
  • exits tmux copy-mode

This would explain why it also copied the contents of my right-side prompt. I'm guessing there's not really any way to avoid it doing that?

VariableVixen avatar Dec 24 '19 00:12 VariableVixen

Similar issue to @PrincessRTFM. Is the expected behavior going to always be copying from the cursor location to the end of the line and then some? (I am using Tmux 3.0a)

Highlighting the text to be yanked: highlighting the text Results from yanking the text (using prefix+y) results from yanking

JaredStemper avatar Jul 16 '21 18:07 JaredStemper

It seems that it is not detecting that the shell is in vi-mode. Simply changing it to emacs mode is not an acceptable solution. Many people (such as me) would prefer vi-mode.

TSoli avatar Jul 03 '23 07:07 TSoli