Mouse wheel scrolling in less and vim using urxvt
Old question, but: while this is not possible in urxvt, I made some changes that will add an option (secondaryWheel) to do exactly that, and make it behave like VTE-based terminals.
What this new option does, is pretty simple: when using the mouse wheel, if you’re on secondary screen(*) then no scrolling will occur, and instead 3 “fake” keystrokes will be sent to the running application. So, a wheel up will have the same result as pressing the Up key three times, and wheel down will do the same as pressing 3 times the Down key.
(*) not sure whether this is the “official” term or not, but at least that’s how it’s called in urxvt.
Easy enough, but that does the trick: now when running man
, less
or any other application that uses the secondary screen, you can use the mouse wheel to move around (or whatever said application would do, if you pressed the Up/Down keys).
It should be noted that I'm not sure this is actually how things are done in VTE-based terminals - I never checked - but this does the job, so it works for me.
A little more info, and links to the code & PKGBUILD for Arch Linux can be found there: http://mywaytoarch.tumblr.com/post/14455320734/scrolling-mouse-wheel-improvments-vte-like-in-urxvt
Hopefully this can be helpful to some!
I wrote this for a very similar question, see https://superuser.com/a/1356948/900060
Paste this in $HOME/.urxvt/ext/vtwheel (create the file if it doesn't exist):
#! perl
# Implements a scrollwheel just like in good old vt100's mices
sub simulate_keypress {
my ($self, $type) = @_; #type: 0:up, 1:down
my $keycode_up = 111;
my $keycode_down = 116;
my $numlines = 3;
my $keycode = 0;
if ($type eq 0) {
$keycode = $keycode_up;
} elsif ($type eq 1) {
$keycode = $keycode_down;
} else {
return;
}
for (my $i = 0 ; $i ne $numlines ; $i++) {
$self->key_press(0,$keycode);
$self->key_release(0,$keycode);
}
}
sub on_button_release {
my ($self, $event) = @_;
#my $res_ss = $self->resource("secondaryScroll");
#warn("ressource ss is <$res_ss>");
!$self->current_screen and return ();
#warn("foo, event: <$event->{button}>\n");
if ($event->{button} eq "4") { # scroll up
$self->simulate_keypress(0);
return 1;
} elsif ($event->{button} eq "5") { # scroll down
$self->simulate_keypress(1);
return 1;
}
return ();
}
Then add URxvt.perl-ext-common:vtewheel
to your .Xresources
(or .Xdefaults
) and run xrdb .Xresources
Source: https://aur.archlinux.org/cgit/aur.git/tree/vtwheel?h=urxvt-vtwheel