summaryrefslogtreecommitdiffstatshomepage
path: root/content/7/index.md
blob: fb0fb1bffd44d5d0eb0ffd14848090794a0f8efa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
+++
date = 2021-07-09T22:28:13+02:00
title = "Wrap-around search in less(1)"

[taxonomies]
tags = ["TIL"]
+++

I recently became frightfully aware of how much time I spend in
[`less(1)`](https://greenwoodsoftware.com/less/).

It's never been a utility I gave much conscious thought and I realized that it
is one of those programs that go largely ignored and underappreciated just for
their ubiquity and unobtrusiveness. For most people piping something to
`less(1)` has most likely become second nature. In the same way it is surely
unthinkable for some to read log files and manuals in anything other than
`less(1)`, or use any other pager for the Git suite.

If you've not given `less(1)` a closer look, I invite you to read [its
manual](https://man7.org/linux/man-pages/man1/less.1.html).  There's lots of
neat features you might have missed, like filtering lines with `&`, toggling any
command-line option on the fly with `-`, following input as it appears with `F`,
or opening the current file in an editor with `v`.

A feature I discovered only recently is the "wrap-around search modifier".
Introduced in
[late 2020](https://github.com/gwsw/less/commit/27e2643875e010c30f9d51eb1124855b707806f4)
(past version 565), this modifier obsoletes the common dance of `g` and `n` to
redo the current search on the whole file. Now, if you hit `Ctrl-W` right after
issuing a forward or backward search, `less(1)` toggles search wrap-around.

There is no option to turn this behaviour on automatically. However, it is
possible to override the `/` and `?` bindings using
[`lesskey(1)`](https://man7.org/linux/man-pages/man1/lesskey.1.html).
Put the following in `~/.lesskey`, run `lesskey`
([not needed](https://github.com/gwsw/less/commit/a2137dcb01cbf46f148828a7389540dd5b51bff1)
on versions past 590), and `less(1)` should now wrap the search automatically:

	#command
	/ forw-search ^W
	? back-search ^W