My Internet connection was completely kaput yesterday and is still a little flaky today. To avoid installing new stuff, I’m going to jump out of alphabetical order slightly, and talk about less.
“Talk about less,” not “talk less.” This is a blog, after all. Talking less is an impossibility for most people who do this. 😐
Either way, I have been looking forward to this, simply for the chance to work in some double entendres.
But also because digging more into less has exposed a few of my own misconceptions, and shown that you can do much more with less, and sometimes even more with less than with most. 🙂
What is likely invisible to less users, is the fact that less takes on quite a few options, and will do a lot more if given the chance.
And what was a misconception for me until earlier today, is that less is designed after more. I thought it was more that followed less.
You can watch this gif while you wrap your head around that last one.
My preliminary suggestion — and this is just me — is that I prefer to see some kind of indicator bar. Press the hyphen and then a capital M for a long status display.
Most people use less to skim or search, and so let’s do that first. You can navigate less with the keystrokes from vi(m), which may score another point for the vim team.
Search is done with the slash key, and you can follow that with the traditional asterisk and question mark wildcards. That much you might expect.
By default, less will highlight (or reverse) the terms it finds. You can turn off the highlighting with ESC-u.
All that is fine and dandy, but here’s something cool: less can page through several files in a row, and search through all of them at once.
So if you have a … I don’t know, maybe a list of movies or songs, and you don’t know where the title appears, less can search through all of them and find it for you. Here’s a list scalped off a movie directory eons ago. Enter a search term, and bounce to the next file with ESC-n.
more doesn’t do this. most can do it, but it’s not an explicit part of the search feature; you’re actually searching, then switching files, then searching again. Not the same thing.
So what if you’re sifting through something quite dense, and you’re lost in all the reversed text? How about a status column, to catch your eye and help you find the current term? Enter this while less is running, or as a command flag.
That’s a hyphen, followed by a capital J. You should get a single column to the left of your search results, marked with a reversed asterisk (how very C64).
Un-highlight (with ESC-u) and you’re left only with asterisks marking lines with matching terms. Nifty.
less also does some greppish stuff. Instead of the slash, try searching with the ampersand.
What’s happening there? Well, instead of all the text and highlighting matching lines, you’re getting a sifted list of matching stuff only. Lines that don’t contain “The” aren’t shown. Woo-hoo, a pageable grep.
To really satisfy the need for recursivity, try using the ampersand again, to filter it down to two or three.
If you’re paranoid like me it’s worth mentioning that less stashes your search history and a few other notes about it’s brief life experiences in your home folder as .lesshst, which I promptly delete. Nothing incriminating in there, I just don’t like leftovers clogging up my home directory.
You can also configure less to run with the same options each time, like a customized status bar or personalized key commands (ahem, emacs fans).
But all of this you already knew, because less is in the default software for about 90 percent of the distros out there, including yours, right?
Maybe you did and maybe you didn’t at least now you know more. I mean less. I mean more about less. I could go on like this for days. … 😈