Friday, 7 June 2013

How to find last matching line with ex?

How to find last matching line with ex?

The ex command $ navigates to the first character of the last line. Therefore, when doing a backwards search it skips the line it's currently on. How do I navigate to the last character with ex, or alternatively search for the last occurrence of a regular expression?
Example:
$ cd -- "$(mktemp --directory)"
$ printf '%s\n' foo bar foo bar > test.txt
$ ex -c '$' -c '?bar' -c 'visual' test.txt
At this point the cursor is on line 2 instead of line 4, as expected. Using ex -c '?bar' -c 'visual' test.txt produces the same result, even though I'd expect it to find the last line when wrapping around (vim does).

No comments:

Post a Comment