5

Can I setup less program to exit from it by pressing ESC key?

0

2 Answers 2

10

To bind Esc+Esc to quit with lesskey, do the following:

  1. Create a ~/.lesskey file with the line:
\e\e quit
  1. Run lesskey. This will create a binary ~/.less file used by less.

  2. Use less as usual. Esc+Esc will do a quit.

If you no longer want your bindings, you can remove the ~/.less file.


For more details, see man lesskey or lesskey.nro in the less package source.
Debian -- Details of source package less in wheezy

SYNOPSIS
       lesskey [-o output] [--] [input]

The input file is a text file which describes the key bindings.
If the input file is "-", standard input is read.
If no input file is specified, a standard filename is used
as the name of the input file, which depends on the system being used:
On Unix systems, $HOME/.lesskey is used;
on MS-DOS systems, $HOME/_lesskey is used;
and on OS/2 systems $HOME/lesskey.ini is used,
or $INIT/lesskey.ini if $HOME is undefined.
2
  • Nice one! This works well!
    – Sparhawk
    Feb 7, 2015 at 13:46
  • I had just found this while poking around in the source only to realize this answer was here already. I really appreciate that the consideration the developers have shown for the user by including lesskey.
    – iyrin
    Feb 8, 2015 at 0:17
7

Not really.

less has many functions bound to ESC + something else. See the manpage: ESCv, ESCn, ESCF, many others. You wouldn't be able to type any of those is less exited upon receiving just ESC.

Concievably, you could rebind all those functions to other keystrokes or live with being unable to type them, and rebind ESC to quitting, but it still wouldn't be a good idea.

It's not a good choice of key to use. In VT100 (the terminal emulation used basically everywhere these days) all terminal control sequences begin with the ASCII ESC character. This means that every time you press something like an arrow key, your terminal sends ESC followed by other stuff. When you press the ESC key, your terminal also sends ESC, but it's not followed by anything. How can software tell the difference after having received an ASCII ESC character? It is forced to wait a some time to see if anything follows the ESC. So things bound to ESC alone always incur a delay, a time lag before the software can respond.

8
  • 1
    It a really good explanation. As you said, many functions of less bound to esc+something else. It would be cool to setup quit from less by pressing Esc+Esc. Is it possible? Feb 7, 2015 at 9:19
  • Terminal control sequences starting with ESC are sent to the terminal, not received from it. Pressing the Escape key adds keycode 27 to the input stream immediately... You can test this yourself with the code at shtrom.ssji.net/skb/getc.html Feb 7, 2015 at 9:30
  • 1
    @ArturEshenbrener You can bind to ESC+ESC with \e\e. See the lesskey(1) man page.
    – vinc17
    Feb 7, 2015 at 9:33
  • @StephenKitt terminal control sequences starting with ESC are both sent to the terminal and received from the terminal. An example of from the terminal is an arrow key. An example of to the terminal is an instruction to move the cursor.
    – Celada
    Feb 7, 2015 at 9:36
  • 1
    @Celada See my answer on how to use lesskey.
    – vinc17
    Feb 7, 2015 at 13:21

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.