1

follow urxvt: scroll just one line

How can we set keybindings so that shift+up can scroll one line up in xterm?

Chenming Zhang
  • 1,037
  • 1
  • 12
  • 14

2 Answers2

6

Use the X resources documented in the XTerm man page, particularly the "ACTIONS" section about 80% of the way down.

Create a file ~/.Xresources and put in it:

XTerm.VT100.translations: #override \
    Shift <Key>Up: scroll-back(1) \n\
    Shift <Key>Down: scroll-forw(1) 

"Translations" is the base Xt library's name for key and mouse bindings. This sets bindings for the VT100 (terminal emulation) component of XTerm, overriding any existing bindings and setting Shift-Up to scroll up (or "back") one line, and Shift-Down to scroll down ("forw"ard) one line. We're making one long line so we're using backslashes at the end to mark continuation.

As with any use of .Xresources, you will need either to have the XENVIRONMENT variable set pointing to the right place, or use xrdb -merge ~/.Xresources to load the file into the resource manager explicitly.

Michael Homer
  • 76,565
  • Actually, XAPPLRESDIR is preferable to XENVIRONMENT. The former lets you configure regular app-defaults files in your own directory, the latter forces everything into a single file. xrdb ... is like the latter. – Thomas Dickey May 02 '16 at 01:05
3

Michael Horner's answer is close, but overlooks a detail:

XTerm.VT100.translations: #override \
    Shift <Key>Up: scroll-back(1) \n\
    Shift <Key>Down: scroll-forw(1)

uses the default units for scrolling. To ensure that you get lines, you need to add a parameter:

XTerm.VT100.translations: #override \
    Shift <Key>Up: scroll-back(1,line) \n\
    Shift <Key>Down: scroll-forw(1,line) 

The manual page mentions the units in describing scroll-back and scroll-forw, but does not mention in that paragraph that the default is set by another resource, scrollLines:

   scrollLines (class ScrollLines)
           Specifies  the number of lines that the scroll-back and scroll-
           forw actions should use as a default.  The default value is 1.
Thomas Dickey
  • 76,765