less already uses j/k for vertical scrolling, but not h/l for horizontal scrolling (in --ch mode). The l key isn't bound to anything anyway, and h is just a synonym for H, so I wouldn't overwrite any important bindings.

How can I make h and l scroll horizontally?

  • 3
    See man lesskey – Marco Dec 22 '12 at 12:24

man less tells us the following:

You  may  define your own less commands by using the program lesskey
(1) to create a lesskey file.  This file specifies a set of  command
keys  and  an  action  associated  with  each key.  You may also use
lesskey to change the line-editing keys (see LINE EDITING),  and  to
set  environment  variables.  If the environment variable LESSKEY is
set, less uses that as the name of  the  lesskey  file.   Otherwise,
less  looks  in  a  standard  place  for  the  lesskey file: On Unix
systems, less looks for a lesskey file called "$HOME/.less".

It tells us to use lesskey to generate a lesskey file reading man lesskey fills in the details. You can put the following in the lesskey input file (~/.lesskey by default)

h left-scroll
l right-scroll

Then run lesskey, and it will generate an output file (~/.less by default) for you.

As far as I can tell, you can't do character-by character horizontal scrolling.


You can set your own key bindings with the lesskey program. Create a file called .lesskey in your home directory containing your keybindings, then run the lesskey command to convert them into a form that less understands (the compiled bindings are stored in ~/.less).

There is no command that scrolls one character left or right. You can do that by passing the numeric argument 1 to the left-scroll and right-scroll commands. You can't directly set a binding for a command with an argument, but you can set a binding to run a command and then parse more keys. So run the noaction command, then parse a key sequence that runs the scroll command with the desired arguments.

h noaction 1\e(
l noaction 1\e)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.