Neat less Tricks

If you forget which file you’re paging (I do all the time), hit ‘=’.

If you always (or usually) want line numbers, add this to your .bashrc file:

# make less show line numbers
export LESS='-N'

This sets the environment variable that less reads, assigning it the options that you want. -N and -n toggle the line numbers display. They work while you’re already in less, too (with the dash).

If you have vi/vim on your system, hitting ‘v’ (no dash) while paging with less will drop you into it. That way, you can page to the location in the file you want to edit and not worry about hitting random keys on the way.

In fact, vi navigation commands (hjkl) work in less, too.

Search for terms with the slash, like this:

/swap

Your search terms will be highlighted:
vimsearch
less will search forward (‘?’ searches backward), and search terms are case sensitive. The arrow keys will let you scroll back through your previous searches.

If you can’t remember any of this while you’re paging, hit ‘h’ (no dash) and less will display its help screen. To get back to your file, hit ‘q’ (although you don’t need me to tell you that, because it’s on the help screen :-)).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s