1

When you run a search and replace on visual-line selected text, it shows this :'<,'>s/foo/bar

Is it possible to get it to show line numbers instead of <>?

1

You can create a mapping to do this

xnoremap : :<c-u><c-r>=line("'<")<cr>,<c-r>=line("'>")<cr>

When you hit : in visual mode it will delete the '<,'> that is normally put there with <c-u>. Then it will insert the line number for the '< and '> marks separated by a comma. It does this with

<c-r>=line("'<")<cr>

where <c-r>= opens the expression register which allows you to type in an arbitrary expression and insert the result.


I don't recommend using this since it makes it almost impossible to repeat the visual selection command on a new region, since the history will now have line numbers instead of the marks. The line numbers can't change between invocations but the marks can.

| improve this answer | |
0

My CmdlineSpecialEdits plugin has (among many others) a CTRL-G ' mapping that changes symbolic ranges like '<,'> to the actual line numbers (e.g. 3,42), and vice versa. It also corrects addressing out of bounds (<= 0 and larger than the last line number) and backwards ranges.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.