10

Is there a way to search, while I'm typing in less? Just like the vim option, set incsearch.

As I didn't find a proper way to do it, is there any similar tool that can do it?

  • Why Don't you use vim as your pager!? – user1146332 Sep 18 '12 at 15:36
  • @user1146332 hmm, I don't know if VIM could handle a stream directly, but seems ire_and_curses has given the right way to use vim – daisy Sep 18 '12 at 15:48
  • With '--' as command line argument vim reads from stdin (posted from mobile phone) – user1146332 Sep 18 '12 at 16:07
16

You can do a search from the command line:

less -ppattern filename

Or, once inside less, use / followed by your pattern to do interactive searching (forwards). n and N repeat the search in the forward and reverse direction, respectively. That's the bare minimum you need to know; there are many more commands for more complex or specific searches.

Edit: To respond to your updated question, there's currently no way to do immediate incremental searching with less. Have you considered using view instead (opens Vim in read-only mode, so will use your incsearch setting)? Vim can be made even more pager-like with the vimpager script.

Some additional information: There is an open bug on the Ubuntu bug-tracker for incremental search support, but it doesn't look like it's going anywhere soon. Somebody has implemented incremental support on a github fork, but obviously you're going to have to compile a custom less to use that.

(And apart from the Ubuntu enhancement request there is currently (as of 2016-05-17) no such enhancement request on the official less bugtracker.)

  • Sorry, but the initial question i posted wasn't clear, can you check my updated question? – daisy Sep 18 '12 at 15:13
  • +1 for recommending view (read-only vi) - i hate it when people use vi instead of less or view, and lock the file unnecessarily. – cas Sep 18 '12 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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