Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I have code similar to this:

<%= article.body %></td>
<%= %></td>
<%= link_to 'Show', article %></td>
<%= link_to 'Edit', edit_article_path(article) %></td>
<%= link_to 'Destroy', article, :confirm => 'Are you sure?', :method => :delete %></td>

I want to delete the HTML tags from the end of the lines in Vim. The only way I thought of was a search and replace. I know I can insert and append text to multiple lines, but is there a way to delete text from multiple lines?

share|improve this question
What's wrong with find and replace? – frabjous Jan 30 '11 at 2:56
@frabjous, nothing is wrong with find and replace, I just thought that if you can add text to multiple lines, you would be able to delete text from multiple lines. – mbreedlove Jan 30 '11 at 4:57
You can delete text from multiple lines... with find and replace. That really seems like the natural way to do it; it isn't clear to me what kind of commands could be used that would be more natural or require fewer keystrokes, even theoretically. – frabjous Jan 30 '11 at 15:47
up vote 3 down vote accepted

Search and replace, after '<', a string of characters not (^) the '<' character, until your reach a '>' that is also at the end of the line:




share|improve this answer
The plus needs to be escaped and there's no need for the g since it's an anchored pattern. – Dennis Williamson Jan 30 '11 at 5:07
Great job explaining the regex, it's really helpful. However, I'm looking for a way to delete characters off multiple lines. – mbreedlove Jan 30 '11 at 5:08
That's what the % is specifying, that the substitution be done for every line. See :help 10.3, :help :range, :help 04.4 and :help visual.txt for more possibilities. – garyjohn Jan 30 '11 at 11:54
Dennis: thanks for the comment. I've corrected the 'plus' above. I'm a habitual 'g' user, so I tend to stick it in all the time. But you are right -- works fine without the 'g'. – Rolnik Jan 30 '11 at 15:49

That's one valid method.



An Ex command is one starting with a colon (':'). The command works on the specified range (default whole file), by executing the Ex command cmd for each line matching . Before executing cmd, "." is set to the current line.

This seems an equally facile way to run a command on a group of files.

share|improve this answer

Your Answer


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.