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).
Using Vim 7.3.
ex -c '$+1' -c visual test.txt
shows that it's at the bottom of the file. Nice! – l0b0 Jun 07 '13 at 15:19