But there are (at least) 150 Psalms! You're going to need more less tips to match that.
-L: skip preprocessing the input file. When opening rotated log files with the names like logfile.1, logfile.2... the default preprocessor on some distros will recognize them as man page source and helpfully pipe through nroff. If the file is largish this introduces an annoying pause. Using -L skips all that.
Ctrl-R as the first character of a search string will search for that literal string, not the regular expression. Nice if you have regex metacharacters in the search string and don't want to bother with escaping (and don't need the regex facilities, of course.)
Admittedly, they are a bit slow sometime and sure, you could use `grep -v` then pipe which is way faster, but they've saved me on removing noise from logfiles from time to time when you don't always know what to filter beforehand :).
EDIT: It was in TFA.
I have a single line in my config[1] which binds s to back-scroll, so that d and s are right next to each other and I can quickly page up/down with one hand.
If you’re on macOS, you may not be able to use this unless you install less from Homebrew, or otherwise replace the default less.[2]
[1] https://github.com/jez/dotfiles/blob/master/lesskey#L2
[2] https://apple.stackexchange.com/questions/27269/is-less1-mis...
" ... desirable if the deinitialization string does something unnecessary, like clearing the screen."
I prefer to not clear the screen. I usually want to continue to refer to something or even copy/paste from the content to my current command line.
Also useful for privilege escalation...
If a script running as root uses less (or vi), just do "!bash" and you have a root shell. Note that systems that let you do this are usually pretty weak, and there are often many other ways to get root access, but this is a particularly simple one that I used a few times in the past.
...And combined with some of the other options in the post, my go-to has been "less -SEXIER" for a long time. Specifying E twice doesn't seem to do anything except make this easier to remember.
My mind was blown when finding out its really just "keep on polling after EOF". Meaning there is absolutely no difference between opening a file normally and "following" a file - and software could easily switch between the two "modes" on the fly.
Less provides an alternative of <C-x> to stop following, but that is intercepted by most shells.
(I suppose I could `tee`, but then I would always dump to a file even if it ends up being useless output.)
git uses "less -FRX" by default. This is how I learned about -F.
(To be pedentic, git uses "LESS=FRX less", which accomplishes the same thing.)
https://github.com/charmbracelet/glow/compare/master...fragm...
Having to set bookmarks and remember them is a PITA I can usually do without. If I'm looking at "normal" log output, it's usually set up in a nice aggregator somewhere, where I can easily exclude noise and otherwise uninteresting output.
In a recent discussion on Reddit I shared a number of tips about the common utility less(1) that others found helpful so I figured I'd aggregate some of those tips here.
While most folks invoke less at the tail of a pipeline like
$ command | less
Invoking less in a pipeline
you can directly provide one or more files to open
$ less README.txt file.c *.md
Invoking less directly
When reading a document, sometimes you want to view another file, adding it to the file list. Perhaps while reading some C source code you want to also look over the corresponding header-file. You can add that header-file to the argument list with :e file.h
You can navigate between multiple files using :n to go to the next file in the argument-list, and :p for the previous file. You can also use :x to rewind to the first file in the argument-list similar to how :rewind behaves in vi/vim.
While I rarely feel the need to, if you have finished with a file and want to keep your argument list clean, you can use :d to delete the current file from the argument-list.
Use «count»G to jump to a particular line-number. So using 3141G will jump to line 3141. It helps to display line numbers.
Similarly, using «count»% jumps to that percentage-offset of the file. So if you want to go to ¾ of the way through the file, you can type 75% to jump right there.
While many folks know you can search forward with /«pattern» and some people know you can use ?«pattern» to search backwards, or use n/N to search again for the next/previous match, less provides modifiers you can specify before the pattern to modify its behavior:
!
Find the next line that doesn't match the pattern
*
search across multiple files, starting from the current location in the current file
@
rewind to the first file and search from there
@*
rewind to the first file and search from there across multiple files
Thus you would use /@*«pattern» to search for "pattern" starting with the first file.
Using & lets you specify a pattern and filter the displayed lines to only those matching the pattern, much like an internal grep command. If you modify it with !, so it will display only those lines that do not match the pattern, like &!«pattern». I find this particularly helpful for browsing log-files.
You can bookmark points in a file with m followed by a letter, then jump back to that bookmark with ' followed by the same letter. These apply globally across all open files, so if you ma in the third file, then navigate away to other files, using 'a will take you back to the marked location in that third file. I use marks most when reading man-pages, dropping one mark at the OPTIONS section such as mo, and another at the EXAMPLES section, such as me, then bounce back and forth between them with 'o and 'e. While you can use any of the 26 lowercase or uppercase letters (for a total of 52 marks), I rarely use more than two or three either in alphabetical order ("a", "b", "c"), or assigning mnemonics like in the man-page example above.
If the first line on the screen contains a (, [, or {, typing that character will jump to the matching/closing character, putting it on the bottom line of the screen. Similarly, if a closing ), ], or }, character appears on the last line, typing that closing character will jump to the matching/opening character, putting it at the top of the screen. I find it a little disorienting if they fall less than a screen-height apart because what feels like a forward motion to find the next matching close-bracket might actually result in shifting the screen down rather than up which feels backwards.
While I don't use it much, you can also specify match-pairs using alt+ctrl+f or alt+ctrl+b followed by the opening/closing pair of characters such as alt+ctrl+f<> to define a "<"…">" pair and jump between them in a manner similar to the (/), [/], and {/) motions.
While the man-page documents many flags you can pass on the command-line, you can also toggle boolean options from inside less. I find this particularly helpful when I've fed the output of a long-running process to less and don't want to re-run it because it will take a long time. Instead of quitting, you can type a literal - followed by the option you want to change. I most commonly want to toggle word-wrap for long lines, so instead of quitting and adding -S at the end of my pipeline, I can type -S directly in less. Options I commonly toggle:
-S
word-wrap (mnemonic "splitting long lines")
-G
search-highlighting
-i/-I
smart-case/case-sensitivity for searches
-R
ANSI-color escaping
-N/-n
show/hide line-numbers
The ! lets you invoke an external command. I don't do this often, but occasionally I want some simple reference like the current date (!date) or to do some simple math (!bc).
$LESSYou might find yourself regularly setting a common group of options so you can put those in your environment (usually in your shell startup file like ~/.bashrc) like LESS="-RNe" if you want to show ANSI colors, show line-numbers, and exit automatically when you reach the end of the file.
less has a few other corners that I've never really used, but figured I'd document here:
While I've used tags in vi/vim to easily jump between definitions. However, even though less provides support for tags generated by ctags. I've never found cause to use them.
The v command will open your $VISUAL editor on the current document.
less lets you redirect the output it has gathered from stdin to a file using the o command (or the O command to overwrite an existing file). This might come in handy because less won't let you edit stdin in an external editor but you can write it directly to a file.