# vim:set ft=conf:
#
# Configuration file for keys for the `less` program.
# It can be used with: `less --lesskey-src ./this-file ...`
# It can also be used with: `LESSKEYIN=./this-file less ...`
#
# See `man less` & `man lesskey` for more details.

# NOTE on how to use `noaction` to give argument to command.
# For example: There is no command that scrolls one character left or right.
# In less program, typing 1 then a key that does {left,right}-scroll would scroll by 1.
# But we can't directly set a binding for a command with an argument in lesskey file.
# To bypass this, we can set a binding to run a no-op command, then parse more keys.
# So run the `noaction` command, then parse a key sequence that runs the scroll
# command with the desired arguments.
# Ref: https://unix.stackexchange.com/a/59194/159811
#
# NOTE: A number then an action (like scroll-left) changes the action-count for the rest of the program execution.
# So to have a key that moves by 1 and a key that moves by 40, I need to change the action-count each time.
# Ref: https://github.com/gwsw/less/issues/205

# --- Define new command keys under the following line:
#command

# Use HJKL to move around by half-a-page
J forw-screen
K back-screen
H noaction 40\e(
L noaction 40\e)

# Use hjkl to move around 1-by-1
j forw-line
k back-line
# See note on how to use `noaction` like this at the top
h noaction 1\e(
l noaction 1\e)

# Disable search highlight
§ undo-hilite

# Restore help binding
\eh help
:h  help

# Use Alt-q to exit and print what was currently visible
# Ref: https://github.com/gwsw/less/issues/36
\eq toggle-option -!^Predraw-on-quit\nq

# Use Alt-w to toggle long lines wrapping
# Ref: https://github.com/gwsw/less/issues/272
\ew toggle-option ^P-chop-long-lines\n

# --- Defines new line-editing keys under the following line:
#line-edit

# Escape-Escape to abort line editing
\e\e abort
# NOTE: a single \e would not work, as it would break every other keybinds using \e
# (there is no `nnoremap` a-la-vim, there's only `nmap`)
