tmux-yank
tmux-yank copied to clipboard
prefix-y isn't working correctly
same with me 😭
- macOS 10.12.5
- zsh 5.3.1
- tmux 2.5
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
prefix–y — copies text from the command line to the clipboard.
Works with all popular shells/repls. Tested with:
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.
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-ato 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
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)
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'
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 what tmux version do you have tmux -V? This feature should work on tmux 2.5 (I'm using it daily).
@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 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 no I don't use copycat plugin here are my configs: base changes and additional stuff
@Seybo does copying works for you when you uncomment this line and comment previous one?
@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
@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 :)
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.
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?
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:
Results from yanking the text (using prefix+y)

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.