Created
March 28, 2012 18:12
-
-
Save namklabs/2228933 to your computer and use it in GitHub Desktop.
Find all closing HTML tags and add a linebreak after each group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Find all closing tags, add a linebreak after each grouping. | |
" This is useful when your whole HTML file has had the whitespace removed by a rogue WYSIWYG editor. | |
" NOTE: I don't think this .vim file would actually work in vim. I just gave it that extension for Gist's sake. | |
:%s@\(<\/\w\{1,10\}>\)\+@&\r@gc | |
" command explanation below | |
" : begin command | |
" % use all lines in file | |
" s search and replace | |
" @ begin what-to-match for search | |
" \( begin grouping | |
" < first character of closing html tag | |
" \ escape closing html tag slash | |
" / closing html tag slash | |
" \w match a letter | |
" \{1,10\} match 1 to 10 letters in a row. I don't think any HTML elements are more than 10 chars long | |
" > end closing html tag | |
" \) end grouping | |
" \+ find more than one closing tag in a row | |
" @ end what-to-match, begin what-to-replace | |
" & insert what was matched in what-to-match | |
" \r insert line break | |
" @ end what-to-replace | |
" g this search can happen more than once per line | |
" c confirm each replacement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! This ranked high in the search results. (I really like the step-by-step breakdown of the regex... great way to reduce the intimidation factor!)