put cursor on found text in less or vi?
Karl Auer
kauer at biplane.com.au
Wed Sep 25 09:38:58 UTC 2024
I am looking at a text file with thousands of very long lines.
When I search in this file, less and vi both position the cursor on the
start of the line containing the found text, though the actual location
of the text may be hundreds, thousands or even tens of thousands of
characters along in the line.
With line wrap on, finding the actual text location means manually
paging through tens or hundreds of pages and eyeballing it. With line
wrap off, it's the same except horizontally :-)
Does anyone know how I can get vi or less to position found text
visibly?
Or failing that, suggest an alternative method?
I have used the grep command below to locate the hits plus a bit of
context (replacing "string with whatever I'm looking for, of course),
but it's very clunky:
grep -n -o '.\{0,50\}string.\{0,50\}' filename | less
I've searched the Internet of course, but can find only very basic
info.
Regards, K.
PS: Any solution that begins with "install emacs" will be ignored. I've
done my time :-)
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au, he/him)
http://www.biplane.com.au/kauer
More information about the ubuntu-users
mailing list