Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Delete some lines with some exceptions
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Delete some lines with some exceptions
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=670 |previous=669 |next=671 |created=March 3, 2004 |complexity=basic |author=Siegfried Bublitz |version=5.7 |rating=0/2 |category1= |category2= }} 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: <pre> :global:^./help/:if (match(getline(line(".")), '^./help/de/') == -1) | delete | endif </pre> ==Comments== Would this also do it? <pre> :g#\./help/[^d][^e]#d </pre> ---- No, because lines like <pre> ./help/dk/and/the/rest/of/the/path </pre> are not deleted. Instead use <pre> g#\(^\./help/\)\(de/\)\@!#d </pre> 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'. ----
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Help
(
view source
)
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab