If I yank some text in the clipboard selection from Vim (e.g. "+yiw
), then quit Vim, I can't paste it in st.
Here's a MWE:
$ git clone https://git.suckless.org/st
$ cd st
$ make
$ ./st
$ echo foo | vim -Nu NONE -
"+yiw
:q
If I press C-S-v
to paste foo
, nothing is pasted on the shell's command-line. I can't paste the text in firefox, nor in xterm, but for some reason I can in urxvt.
OTOH, if I don't quit Vim, but just suspend it with :shell
:
$ ./st
$ echo foo | vim -Nu NONE -
"+yiw
:shell
Then I can paste the yanked text anywhere, including in the current st terminal.
If E558
is raised when you start Vim, this may fix the issue:
$ curl -LO http://invisible-island.net/datafiles/current/terminfo.src.gz
$ gunzip terminfo.src.gz
$ tic -x terminfo.src
Here's another MWE:
$ ./st
$ vim -Nu NONE +'let @+ = "bar"' +q
Again, if I press C-S-v
to paste bar
, nothing is pasted on the shell's command-line.
I can reproduce with Vim (8.1.1200), but not with Nvim (NVIM v0.4.0-620-geada8f5aa).
I'm on Ubuntu 16.04, and I can also reproduce on Ubuntu 18.04 in a virtual machine.
Is it due to:
- a bug in Vim?
- a bug in st?
- a missing configuration in one of them?
If it's a bug, what's the best workaround?
Currently, I'm experimenting this autocmd:
augroup fix_yank_in_clipboard_from_st
au!
au TextYankPost * if v:event.regname is# '+'
\ | call system('echo ' . shellescape(@+) . ' | xclip -selection clipboard')
\ | endif
augroup END
It requires the $ xclip
shell utility.
The autocmd is called whenever some text is yanked to invoke $ xclip
and make it write the text in the clipboard selection.
One issue with the current code is that it adds a trailing newline at the end of the yanked text.
Edit:
The behavior of st seems normal.
I was confused by the behavior of urxvt which allows you to paste the text yanked in the +
register, back into a urxvt terminal, even after quitting Vim.
But it requires some custom configuration; i.e. these lines in ~/.Xresources
:
URxvt.perl-ext-common: selection-to-clipboard,pasta
URxvt.keysym.Control-Shift-V: perl:pasta:paste
And this pasta
perl script in ~/.urxvt/ext
:
#! /usr/bin/env perl -w
# Usage: put the following lines in your .Xdefaults/.Xresources:
# URxvt.perl-ext-common : selection-to-clipboard,pasta
# URxvt.keysym.Control-Shift-V : perl:pasta:paste
use strict;
sub on_user_command {
my ($self, $cmd) = @_;
if ($cmd eq "pasta:paste") {
$self->selection_request (urxvt::CurrentTime, 3);
}
()
}