Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When searching for terms in less, I'd like to see lines above and below a search result. Can less be configured to do this?

Simple less usage is: - Open file - Search by typing "/" - Move to new search matches with "n" But each match is shown on the first line of the terminal. You can not see the lines that came just before a search result without moving the view back a few lines. It's tedious to do that as you skim through a file.

share|improve this question
2  
Can you provide more information on what you are trying to do? I think I understand, but it's not at all clear. –  ChrisF Mar 14 '11 at 21:25
    
Reworded question to be more explicit. –  Vincent Scheib Mar 14 '11 at 21:57

1 Answer 1

up vote 3 down vote accepted

You can use the -j option. From within less, type - then j then enter a number of lines below the top of the screen for the target line to be displayed (e.g. 12).

You can start less using this option:

less -j12

or set the LESS environment variable to include it:

export LESS=-j12

My $LESS is:

-iMFXRj4a#1

You can include setting the environment variable in your ~/.bashrc file to make it persistent.

share|improve this answer
3  
-j.5 causes "middle of screen". –  Vincent Scheib Mar 15 '11 at 0:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.