1

I see many questions about keybinds in urxvt, but I don't see this exact one. I'd like to use control+v in order to paste into the terminal. (without the shift. or alt/meta key. etc.)

My goal is to be able to paste from other applications like a text editor or Chrome. (noting this in case it's relevant to the "type" of paste-function/clipboard involved, as I understand there may be more than one.) I'm running Ubuntu 20.04 with i3 window manager.

Here's what I've tried, modified from this answer, but it didn't work.

I added the following in ~/.Xresrouces

! Do I need to remove/change any default bindings first?
URxvt.keysym.Control-Meta-v: builtin-string:

! use control+v for "paste"
URxvt.keysym.Control-V: eval:paste_clipboard

! I read these are needed to disable other behavior of control key
URxvt.iso14755: false 
URxvt.iso14755_52: false

After saving the file above, I entered the command to reload it:

xrdb -merge .Xresources

... but after restarting urxvt, even after rebooting, I still cannot paste using control+v.

What lines do I need to add to .Xresources file, or what do I need to do otherwise, in order to use control+v as the shortcut for "paste" in urxvt?

2
  • I'm not sure you can override Ctrl + C because it will simply break your terminal but Ctrl + V should be possible :-) But still I wouldn't go this way because it may mess with your muscle memory: you'll have to use Ctrl + Alt + C to copy and Ctrl + V to paste. Commented Dec 14, 2021 at 16:37
  • Sorry about the irrelevant reference to "C" here. I've removed it. Commented Dec 14, 2021 at 17:30

1 Answer 1

2

It can be done using urxvt's scripting feature and xdotool. urxvt can load Perl scripts which can trigger actions for key combos. My urxvt configuration uses this feature to feed ctrl+shift+v into the terminal whenever ctrl+v is pressed.

This is really only half of a solution though, as the way I've implemented it involves a hacky workaround (the sleep 0.25), in practice this has the desired effect and doesn't cause any problems except the small amount of lag, but in theory it's not guaranteed to work.

in .Xresources:

URxvt.keysym.Control-Shift-V: eval:paste_clipboard
URxvt.perl-ext-common: default,ctrl_v_paste
URxvt.iso14755: false
URxvt.iso14755_52: false

create /usr/lib/x86_64-linux-gnu/urxvt/perl/ctrl_v_paste:

#! /usr/bin/perl

=head1 NAME

paste - paste with ctrl v

=head1 DESCRIPTION

paste with ctrl v

=cut

sub on_init {
   my ($self) = @_;

   my $hotkey = "C-v";

   $self->bind_action ($hotkey, "%:start")
      or warn "unable to register '$hotkey' as hotkey\n";

   ()
}

sub on_action {
   my ($self, $action) = @_;
   
   $action eq "start"
      and $self->enter;

   ()
}

sub enter {
   my ($self) = @_;
   system("sleep 0.25 && xdotool getactivewindow key ctrl+shift+v &");
}

edit: since the time that I last answered I've found a better way to paste, replace system("sleep 0.25 && xdotool getactivewindow key ctrl+shift+v &"); with:

my $clipboard = `xclip -o`;
$self->tt_paste($clipboard);
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .