Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .