I have code similar to this:

<%= article.body %></td>
<%= article.author %></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?

  • 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

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




  • 1
    The plus needs to be escaped and there's no need for the g since it's an anchored pattern. 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.

From http://vim.wikia.com/wiki/Power_of_g


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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