I'm not sure it's possible or not, but one of the things I find I need to do often is to replace the contents of the file, but I want to use the current line number as a replacement option. So if I had a file like:
This is text to replace XX
This is text to replace XX
This is text to replace XX
I would want to be able to run a regex that would turn that file into:
This is text to replace 1
This is text to replace 2
This is text to replace 3
I've looked around, but I can't seem to find any way of doing this. Is this possible? Does anyone know of a simple way to approach this?
Thanks.
Press y to replace the match or l to replace the match and quit. Press n to skip the match and q or Esc to quit substitution. The a option substitutes the match and all remaining occurrences of the match. To scroll the screen down, use CTRL+Y , and to scroll up, use CTRL+E .
replace in JavaScript. To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring. The string 3foobar4 matches the regex /\d.
For example, the replacement pattern $1 indicates that the matched substring is to be replaced by the first captured group.
:help sub-replace-expression
You can construct a replace expression like:
:s@ xx$@\=" " . line(".")@
... Which works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With