put cursor on found text in less or vi?

Nils Kassube kassube at gmx.net
Wed Sep 25 10:17:28 UTC 2024


On 25.09.24 Karl Auer wrote:
> 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?

As an alternative method I could suggest two solutions.

First you could install joe. It is a cli editor with several key bindings. I prefer the jstar version which uses the good old wordstar key bindings. When you search for a text it will position the cursor at the location found even with very long lines. I don't know of a max. line length but maybe I just never got beyond that limit.

Second you could use a GUI editor. I prefer kate but maybe gedit would do it as well. IIRC kate has a line length limit but I don't remember that max. length. And kate will not only position the cursor at the position found but also highlight the rest of the locations. It will wrap lines so you could easily scroll through the text with the important text locations highlighted.

> PS: Any solution that begins with "install emacs" will be ignored. I've
> done my time :-)

Well, joe also has a version with emacs key bindings, so better don't try jmacs :)


Nils







More information about the ubuntu-users mailing list