This is the less I am using:
less 458 (POSIX regular expressions)
Copyright (C) 1984-2012 Mark Nudelman
In Vim it is \\<
a
less
generally uses vi
syntax, i.e. \<
and \>
unless it has been compiled with the --with-regex=none
configure option or if the regular expression library found at compilation time doesn't provide word boundary search. Your system might also provide a different syntax.
Your version of less
was built with posix regular expressions, as if:
wget http://ftp.gnu.org/gnu/less/less-451.tar.gz
tar zxf less-451.tar.gz
cd less-451
./configure --with-regex=posix
make
However, apparently the cause of whether \<
works or not does NOT depend on this:
\<
will work fine even if you build with the above commands, with posix regex--with-regex
except pcre
, and \<
doesn't work with any of them. If I build with pcre
, then \b
works, instead of \<
.To conclude, I don't know how to make it work with \<
. But you can build yourself with pcre
and then it should work with \b
. If you are not a sysadmin, you probably want to use a --prefix
to install under your home directory, for example --prefix=$HOME/opt
. After the make
step, confirm it works with ./less /path/to/some/file
. If looks good, then finish with make install
.
The character classes [[:<:]]
and [[:>:]]
match beginning and end of word, respectively, in system less
on OS X 10.11.5. I haven't found a way to make the documented short forms \<
, \>
, or \b
work.
(Thanks to denis for the suggestion to check man 7 re_format
.)
First see if man 7 re_format
on your computer has an "Enhanced features"
section which lists \<
etc.
If it does, change one line in less-451/pattern.h
:
#define REGCOMP_FLAG REG_ENHANCED // not REG_EXTENDED
Then ./configure --with-regex=posix; make less
will understand \<
.
This works on Macosx 10.8; on other systems, try following /usr/include/regex.h
.
(Gnu.org has a round dozen
Regular-expression-syntaxes ?! )