2

When using urxvt with customizations from various sources, Ctrl-Left and Ctrl-Right no longer work for moving between words in for example bash and vi. The cause is not the typical missing keysym lines in .Xresources as suggested in other answers, as those exist in the file, and work for other key combinations.

URxvt.keysym.Control-Up:    \033[1;5A
URxvt.keysym.Control-Down:  \033[1;5B
URxvt.keysym.Control-Left:  \033[1;5D
URxvt.keysym.Control-Right: \033[1;5C

In fact, when doing a read or cat -v at the terminal, ^[[1;5A is (correctly) printed for Ctrl-Up, but nothing is printed for Ctrl-Left and Ctrl-Right which instead make the terminal blink. This indicates that the key combination is actually captured before being sent to the terminal.

When using an empty .Xresources files, Ctrl-Left/Right are sent to the terminal as expected. What could be the cause of this issue?

1
  • Does not immediately solve your issue, but avoiding Ctrl-Left and Ctrl-Right in bash/vi would be a winning strategy in the long run (using the keyboard arrows moves one hand away from its optimal position). In bash, substitutes are Alt-F and Alt-B; in vi's command mode, w and b. Jul 3, 2018 at 4:42

1 Answer 1

5

As it turns out, the culprit is the tabbed common Perl extension. tabbed is clobbering Ctrl-Left/Right for moving the current tab left or right respectively. Simply removing tabbed from the URxvt.perl-ext-common fixes the problem, but of course also removes the tab functionality.

In the end, my solution was to create a local copy of tabbed extension and using that instead of the default version. First you may want to find your system's copy of tabbed and copy it to your local extension directory. On my 64 bit Ubuntu 18 system, the file was located at the location in the cp command below. This command of course assumes ~/.urxvt/ext/ already exists.

cp /usr/lib/x86_64-linux-gnu/urxvt/perl/tabbed ~/.urxvt/ext/

To load the local copy instead of the system copy, remove tabbed from the URxvt.perl-ext-common (which would load the default version) and add the following line.

URxvt.perl-ext: tabbed

In ~/.urxvt/ext/tabbed find the function tab_key_press and change it for example as follows:

sub tab_key_press {
   my ($self, $tab, $event, $keysym, $str) = @_;

   if ($event->{state} & urxvt::ShiftMask && !($event->{state} & urxvt::ControlMask) ) {
      if ($keysym == 0xff51 || $keysym == 0xff53) {
         my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };

         --$idx if $keysym == 0xff51;
         ++$idx if $keysym == 0xff53;

         $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]);

         return 1;
      } elsif ($keysym == 0xff54) {
         $self->new_tab;

         return 1;
      }
   }elsif ($event->{state} & urxvt::ControlMask && $event->{state} & urxvt::ShiftMask) {
      if ($keysym == 0xff51 || $keysym == 0xff53) {
         my ($idx1) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} };
         my  $idx2  = ($idx1 + ($keysym == 0xff51 ? -1 : +1)) % @{ $self->{tabs} };

         ($self->{tabs}[$idx1], $self->{tabs}[$idx2]) =
            ($self->{tabs}[$idx2], $self->{tabs}[$idx1]);

         $self->make_current ($self->{tabs}[$idx2]);

         return 1;
      }
   }

   ()
}

This version of the function will make Ctrl-Shift-Left/Right move tabs left and right instead of Ctrl-Left/Right. But another possibility is to remove the code for moving tabs left and right altogether and live without that functionality. This would be done by removing the line

if ($keysym == 0xff51 || $keysym == 0xff53) {

and the following lines to the end of the clause.

1
  • Great answer. (On my Arch system the files were in /usr/lib/urxvt/perl.) But with the newer tabbed-ex extension, this can also be solved by disabling all tabbedex shortcuts with URxvt.tabbed.no-tabbedex-keys: true. Apr 25, 2021 at 9:39

You must log in to answer this question.

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