I had a situation where I wanted to replace FOO with BAR through a file; however, I want to do this only in certain places, for example between lines 68-104, 500-537 and 1044-1195. In practice, I dropped the markers (ma, mb, mc, ...) on the lines of interest to you, and I ran the following:
:'a,'bs/FOO/BAR/g | 'c,'ds/FOO/BAR/g | 'e,'fs/FOO/BAR/g
I had to repeat this several times with different searches and replace the terms s / CAT / DOG, etc., which made me sick to rewrite the command line each time. I was lucky that I had only 3 places in which I wanted to limit my search (imagine if it was 30 or 40, how messy the command line was).
Other than writing a function, is there an easier way to do this?
In the corresponding note. I copied FOO to 's' (search), and BAR to 'r' (replace) and tried the command line
:'a,'bs/\=@s/\=@r/ | 'c,'ds/\=@s/\=@r/ | 'e,'fs/\=@s/\=@r/
It would save me to rewrite the command line every time, but, alas, it did not work. The replacement bit was fine \ = @r, but \ = @s in the search pattern gave an error.
Any advice would be appreciated.
vim replace
Dave doran
source share