Fandom

Vim Tips Wiki

Delete some lines with some exceptions

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 670 Printable Monobook Previous Next

created March 3, 2004 · complexity basic · author Siegfried Bublitz · version 5.7


I have several hundred file path names in a buffer, each filling a line, e.g. created with vim tip # 659.

About half of them are help files, starting with './help/' which I want to delete, but I want to keep the german ones, starting with './help/de/'. Here comes how I do it with Vim:

:global:^./help/:if (match(getline(line(".")), '^./help/de/') == -1) | delete | endif

CommentsEdit

Would this also do it?

:g#\./help/[^d][^e]#d

No, because lines like

./help/dk/and/the/rest/of/the/path

are not deleted. Instead use

g#\(^\./help/\)\(de/\)\@!#d

to delete all lines starting with './help/' but keep all lines starting with './help/de/'


g!/\.\/help\/de/d

:help :global


This will only work if each line in the file starts with './help'.


Also on Fandom

Random Wiki