summaryrefslogtreecommitdiffstatshomepage
path: root/content/7
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--content/7/index.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/content/7/index.md b/content/7/index.md
new file mode 100644
index 0000000..fb0fb1b
--- /dev/null
+++ b/content/7/index.md
@@ -0,0 +1,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