History
Article Edit this page Discussion

Delete some lines with some exceptions

From Vim Tips Wiki

(Redirected from VimTip670)
Jump to: navigation, search

Tip 670 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

[edit] Comments

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'.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Delete some lines with some exceptions"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation