How to delete empty lines in multi-ranges in Vim?

Your problem is very similar to the one exposed there.

Your problem is very similar to the one exposed there. Have a loop (with search, called with "no wrap") to search for first the opening tag, then the closing tag. This defines a range onto which you will apply the g/^\s*$/d_.

It may be easier to work backward as some lines will be deleted. EDIT: the folowing one-liner seem to work as well g//,//s/^\s*$\n//g.

I think the g/.../s/.../g one-liner will fail if there's a line matching . * – intuited Jun 16 '10 at 10:36.

This one will clear out all empty lines within blocks: :%s_\zs\_. \{-}\ze_\=substitute(submatch(0), '\n\n\@=', '', 'g')_g WTF: :%s_: starts a substitution command over all lines in the buffer. You can use any character after the s; using one that you're not using within the pattern (in this case _) means you don't have to escape it within the pattern.

\zs\_. \{-}\ze: minimal, multiline match of all characters within blocks. _: delimits the match string from the replacement \=: putting this at the beginning of the replacement indicates that the replacement is a vimscript expression to be evaluated.

Substitute(submatch(0), '\n\n\@=', '', 'g'): The replacement expression is a substitute(...) function call. Submatch(0): this gives the full outer match, in this case everything between \zs and \ze. \n\n\@=: this RE matches any newline that's followed by a newline, without actually advancing past that second newline.

The \@= element is known as a "zero-width lookahead assertion"; :help /\@ will give you more details. The rest of it is pretty simple, just replace the newline with nothing for all occurrences. Note that the second newline (the one spotted by the lookahead) isn't considered part of the match and so doesn't get replaced (at least, not until the next iteration, when it will be replaced if it's followed by a third consecutive newline).

Finally, _g just closes the expression with a g flag to indicate that all instances should be replaced. I think the mnemonic is "global".

Just deserved a +1 for using a vimscript replacement expression – sehe Jul 12 at 9:37.

%s/^$\n// will delete all empty lines from the file. :%s/\(\)\(\n\|. \)*\(\)/\1\r\3/ will delete everything inside of blocks.

This is not what you exactly want, but it could help.

You have deleted all empty-lines. If I want to keep these outside of the ...? – kev Jun 16 '10 at 9:27 @Key I added another command that does interesting stuff. I'm not sure it is feasible in one line though.

– ereOn Jun 16 '10 at 9:39 Thank you. I just figure out how to do it:g//,//s/^$\n// – kev Jun 16 '10 at 9:59 @Kev: please use `` escaping to make code snippets readable. Your :g//,//s/// is nearly illegible now (\/ looks exactly like a V, e.g.) – sehe Jun 16 '10 at 9:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions