Let's say I want to replace '23px' with '500px' in a 3000 line CSS file, where there are dozens of instances of '23px'. I only want to apply this command:

:%s,23px,500px,gc

To lines 550 to 603. Is there any (preferably succinct) way of specifying that I want the command to only apply to 550 to 603? I'm open to also selecting the area visually with SHIFT-V and j/k and then running a command that only applies to the selected/highlighted portion.

link|improve this question

62% accept rate
feedback

1 Answer

up vote 4 down vote accepted

Just specify those lines as your range instead of %. % is just shorthand for <first line>,<last line>.

:550,603s,23px,500px,gc

See

:help :range
:help 10.3

You could also move the cursor to line 550,

550G

then visually select to line 603,

V603G

and then type your command,

:s,23px,500px,gc

Vim will automatically fill in the range for you, so the command line will actually look like this:

:'<,'>s,23px,500px,gc

You can also execute a command on lines matching some pattern. See

:help 10.4
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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