Is there a way to search, while I'm typing in
less? Just like the vim option,
As I didn't find a proper way to do it, is there any similar tool that can do it?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can do a search from the command line:
less -ppattern filename
Or, once inside
/ followed by your pattern to do interactive searching (forwards).
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
It was implemented in https://github.com/gwsw/less/commit/b09a0c452d08afe2da8c9632d4fa768d6474b371 2 months ago, and hopefully will be coming to a distro near us!
less --incsearch filename
Added in this commit on January 13 2021.
Version 598 was released for beta testing on 7 December 2021.
--incsearch to my
LESS environment variable:
export LESS='--incsearch --ignore-case --status-column --LONG-PROMPT --RAW-CONTROL-CHARS --HILITE-UNREAD --tabs=4 --no-init --window=2 ' # Man-db passes extra options to the pager via the `LESS` environment variable, # which Less interprets in the same way as command line options. # The setting is hard-coded at compile time and starts with -i. # (The value is "-ix8RmPm%s$PM%s$" as of Man-db 2.6.2; the P…$ part is the prompt string.) # "--RAW-CONTROL-CHARS": Get color support for 'less' # --no-init: This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen # --HILITE-UNREAD: highlight first unread line after forward movement # https://www.topbug.net/blog/2016/09/27/make-gnu-less-more-powerful/ source $HOME/dot_file/color_less_wf.zsh
These are the differences between version 590 and version 598:
Add the --header option. Add the --no-number-headers option. Add the --status-line option. Add the --redraw-on-quit option. Add the --search-options option. Add 'H' color type to set color of header lines. Add #version conditional to lesskey. Add += syntax to variable section in lesskey files. Allow option name in -- command to end with '=' in addition to '\n'. Add $HOME/.config to possible locations of lesskey file. Add $XDG_STATE_HOME and $HOME/.local/state to possible locations of history file. Don't read or write history file in secure mode. Fix display of multibyte and double-width chars in prompt. Fix ESC-BACKSPACE command when BACKSPACE key does not send 0x08. Add more \k codes to lesskey format. Fix bug when empty file is modified while viewing it. Fix bug when parsing a malformed lesskey file. Fix bug scrolling history when --incsearch is set. Fix buffer overflow when invoking lessecho with more than 63 -m/-n options. Fix display bugs with --header. Fix bug restoring color at end of highlighted text. Fix bug in parsing lesskey file.