익명 11:27

How to assign key W in Less to toggle -S option

How to assign key W in Less to toggle -S option

Toggling word-wrap in Less requires 4 key-presses: - Shift S Enter. In other editors it requires 2 presses: Alt Z or similar.

And toggling the option repeatedly requires one key-press in these other editors.

Can I configure recent Less versions to toggle word-wrap using either one of W, Ctrl+W, Alt+W or any similar one or two-key shortcut ? Without having to also type Enter to dismiss the "Chop long lines (press ENTER)" prompt ?

Adding w toggle-option -S\n in ~/.lesskey does not get rid of the press RETURN prompt.



Top Answer/Comment:

tl;dr:

Put a Ctrl+P before the S


Working example

Here's the minimal .lesskey file I used successfully to achieve exactly what you describe:

$ cat -v .lesskey
#command
w toggle-option ^PS

The ^P is a single character entered using Ctrl+V,Ctrl+P

Note that I don't have a hyphen - nor a carriage-return \n in my tested .lesskey file.


Documentation

The man page for less explains it this way:

- Followed by one of the command line option letters (see OPTIONS below), this will change the setting of that option and print a message describing the new setting. If a ^P (CONTROL-P) is entered immediately after the dash, the setting of the option is changed but no message is printed.

(my emphasis)

Although the above text is for a different situation, it also works in a lesskey file.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다