> I'm trying to delete empty lines on the condition that the previous > line matches a certain pattern, like for example in the next input > file: > foo > foo > > foo > > foo > > bar > > bar > > I would like to remove an empty line if the previous line matches > 'foo'. I came up with: > > :g/foo/+ s/^\s*\n// > > sadly, this doesn't delete the second empty line (at least on my > box: vim 7.1 - debian 5.0). Repeating the same command however ends up > deleting this second empty line as well.
The following worked for me: :%s/\(foo\n\)\%(\s*\n\)*/\1 However, I'm not sure why the following failed: :%s/foo\n\zs\%(\s*\n\)*/ based on all my regexp wonkiness, this looks like it _should_ work. Anybody able to shed light on why it fails to do what I expect (it deletes all but one of the "foo"s)? -tim --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
