Last Updated: February 25, 2016
·
8.794K
· pr3ssh

Copy/paste text in Urxvt (rxvt-unicode) using keyboard

Note: This is a copy of this article. It's only a reminder for me ;)

We are going to use xclip for copy/paste text in Urxvt. First you have to install xclip. Once xclip is installed, create a file called 'clipboard' in '/usr/lib/urxvt/perl/' with this content:

#script to copy/paste text in URXVT
#! perl
sub on_sel_grab {
    my $query = $_[0]->selection;
    open (my $pipe,'| /usr/bin/xclip -in -selection clipboard') or die;
    print $pipe $query;
    close $pipe;
}
sub paste {
    my ($self) = @_;
    my $content = `/usr/bin/xclip -loop 1 -out -selection clipboard` ;
    $self->tt_write ($content);
}
sub on_user_command {
    my ($self, $cmd) = @_;
    if ($cmd eq "clipboard:paste") {
        $self->paste;
    }
}

Add to your .Xdefaults (or .Xresources) the following lines:

URxvt.keysym.Shift-Control-V: perl:clipboard:paste
URxvt.iso14755: False
URxvt.perl-ext-common: default,clipboard

That's it! Enjoy.