How to set up hjkl for less

less

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?

Best Answer

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.

Related Question