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 <>?
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.
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.