{"id":940,"date":"2013-01-18T10:46:45","date_gmt":"2013-01-18T10:46:45","guid":{"rendered":"http:\/\/www.nathankowald.com\/blog\/?p=940"},"modified":"2016-11-13T17:54:42","modified_gmt":"2016-11-13T17:54:42","slug":"vim-delete-lines-that-dont-match-pattern","status":"publish","type":"post","link":"https:\/\/www.nathankowald.com\/blog\/2013\/01\/vim-delete-lines-that-dont-match-pattern\/","title":{"rendered":"Vim: delete lines that don&#8217;t match pattern"},"content":{"rendered":"<p>Ex command <strong>:v<\/strong> to the rescue!<\/p>\n<pre class=\"prettyprint lang-sh\">:v\/pattern\/d<\/pre>\n<p>Using <strong>:g!<\/strong> will give you the same result as using <strong>:v<\/strong>.<br \/>\n<strong>:g<\/strong> finds lines that do match a pattern.<\/p>\n<p>I had a large list of locations. I wanted to keep only the locations containing hyphens and delete the rest so I used this: <strong>:v\/-\/d<\/strong><\/p>\n<p><strong>:v<\/strong> &#8211; find lines not matching your pattern<br \/>\n<strong>d<\/strong> &#8211; delete matches<\/p>\n<hr style=\"margin-top:70px;\">\n<h3>Recently Loved Articles  <a href=\"http:\/\/del.icio.us\/rss\/n8kowald\/shared\"><img decoding=\"async\" class=\"noborder\" title=\"Subscribe to my loved articles feed\" src=\"\/\/www.nathankowald.com\/images\/feed-small.png\" alt=\"\" \/><\/a><\/h3>\n<ul class=\"lovedarticles\">\n<li><a href=\"http:\/\/imgur.com\/a\/ISNRG#0\" target=\"_blank\">2013 CES: Press Conference Slides &#8211; Imgur<\/a> &ndash; <em>Can&#8217;t wait!<\/em><\/li>\n<li><a href=\"http:\/\/rossduggan.ie\/blog\/programming\/naming-things\/\" target=\"_blank\">Naming things | Ross Duggan<\/a> &ndash; <em>Great article about naming software<\/em><\/li>\n<li><a href=\"http:\/\/betabeat.com\/2013\/01\/programmer-outsources-his-job-to-china-so-he-can-get-paid-to-screw-around-on-reddit-all-day\/\" target=\"_blank\">Programmer Secretly Outsources His Job to China So He Can Get Paid to Screw Around on Reddit | Betabeat<\/a><\/li>\n<li><a href=\"https:\/\/chrome.google.com\/webstore\/detail\/page-turner\/fpbddhncmmhkaofhcnkjgcdbgcmomebo\" target=\"_blank\">Chrome Web Store &#8211; Page Turner<\/a> &ndash; <em>My first published Chrome Extension :D<\/em><\/li>\n<li><a href=\"http:\/\/lifehacker.com\/5975599\/ebook-glue-transforms-blogs-into-ebooks\" target=\"_blank\">Ebook Glue Transforms Blogs Into Ebooks<\/a> &ndash; <em>Looks good. Try it.<\/em><\/li>\n<li><a href=\"http:\/\/mystilleef.blogspot.co.uk\/2006\/11\/indentation-with-spaces-considered.html\" target=\"_blank\">Indentation With Spaces Considered Harmful<\/a> &ndash; <em>Using tabs means everyone can use their preferred tab widths in their IDEs.<\/em><\/li>\n<li><a href=\"http:\/\/javascriptshow.com\/\" target=\"_blank\">The Javascript Show<\/a> &ndash; <em>Good JavaScript podcast I found.<\/em><\/li>\n<li><a href=\"http:\/\/thoughtbot.github.com\/vimulator\/\" target=\"_blank\">Vimulator<\/a> &ndash; <em>Helpful for people learning Vim.<\/em><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?feature=player_embedded&#038;v=wmg-sYnMIrA#!\" target=\"_blank\">Drugs at work &#8211; YouTube<\/a> &ndash; <em>haha!<\/em><\/li>\n<li><a href=\"http:\/\/techcrunch.com\/2013\/01\/12\/10-reasons-why-2013-will-be-the-year-you-quit-your-job\/\" target=\"_blank\">10 Reasons Why 2013 Will Be The Year You Quit Your Job | TechCrunch<\/a> &ndash; <em>Good read<\/em><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Ex command :v to the rescue! :v\/pattern\/d Using :g! will give you the same result as using :v. :g finds lines that do match a pattern. I had a large list of locations. I wanted to keep only the locations containing hyphens and delete the rest so I used this: :v\/-\/d :v &#8211; find lines [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9,7],"tags":[],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry","category-vim","category-web-development"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/comments?post=940"}],"version-history":[{"count":31,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":1785,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/940\/revisions\/1785"}],"wp:attachment":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/media?parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/categories?post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/tags?post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}