Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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