Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut for word boundary in `less`?

Tags:

unix

This is the less I am using:

less 458 (POSIX regular expressions)
Copyright (C) 1984-2012 Mark Nudelman

In Vim it is \< and \>, in most other regex it is \b.

like image 770
Steven Lu Avatar asked Mar 30 '14 05:03

Steven Lu


2 Answers

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.)

like image 95
Jack Foy Avatar answered Sep 20 '22 05:09

Jack Foy


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:

  • In Debian/Linux, \< will work fine even if you build with the above commands, with posix regex
  • In Mac OS X, I tried all possible values of --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.

like image 38
janos Avatar answered Sep 22 '22 05:09

janos