238

I just found out I can use less with multiple files. less status line tells me (END) - Next: file2.txt

But how do I navigate previous/next from less?

migrated from stackoverflow.com Oct 18 '11 at 8:23

This question came from our site for professional and enthusiast programmers.

263

We read in the manpage:

       :n     Examine  the next file (from the list of files given in the com‐
              mand line).  If a number N is specified, the N-th next  file  is
              examined.
       :p     Examine the previous file in the command line list.  If a number
              N is specified, the N-th previous file is examined.
  • 8
    :e [file] Examine a new file. -- i.e. open a new file while less is open – JellicleCat Jun 30 '14 at 15:30
  • 55
    +1 stack exchange is faster than manual grep through man to find the right part when you're not sure how it's described. – Nathan Aug 5 '14 at 18:31
  • 4
    If a number N is specified - how to specify this number (can't find answer in the manpage)? – Piotr Dobrogost Nov 25 '14 at 16:53
  • 14
    @PiotrDobrogost: Good question. I had to fiddle a bit with it myself. Turns out the number precedes both the colon and the n or p. E.g., 3:n moves one to the third-next file. – Stephan202 Nov 25 '14 at 17:35
  • 5
    @ardnew You are very unlikely to get any upvotes on that comment - anyone who agrees with you is unlikely to come across this question! – T.C. Proctor Sep 21 '17 at 15:29
31

Type :n and :p.

26

Found out from :h (help window) that I can use :p (for previous) and :n (for next)

  • 10
    Teach a man to fish. I didn't know you could :anything, but now I know how to look using :h... – Mitch Kent Oct 15 '14 at 9:51
  • 4
    Just to clarify, you only type h for help, without the colon (the colon is already there). However, you have to type :n or :p with an explicit colon to go to next/prev file. – wisbucky Sep 27 '17 at 21:24
10

Note: you actually have to type the : for these commands (even though there is a colon visible already).

:n jump to next file
:p jump to previous file
:x jump to first file

3:n jump 3 files ahead
3:p jump 3 files back
3:x jump to 3rd file

:f print current file name/info (helpful if you forget where you are)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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