Thermocup

Thermo insulated coffee cup

Spring 2014 Update: Strictly 120

Using VIm’s “:v” Command to Delete All Lines NOT Containing a Pattern

Addendum to my previous post

Using VIm’s “Negative Lookahead” to Delete All Lines NOT Containing a Pattern

I received a message from a reader who goes by the name of “bw1″ who points out that my task “to delete all lines in the current file not containing the string foo” can easily be accomplished by issuing this command

:v/foo/d

:-) I should read the VIm documentation once in a while!

In The Meantime

Drum’n’Bass, 164bpm

Using VIm’s “Negative Lookahead” to Delete All Lines NOT Containing a Pattern

UPDATE:
Please note that “bw1″ has notified me of a much simpler solution than what is described here; please see

Using VIm’s “:v” Command to Delete All Lines NOT Containing a Pattern

Some statements have been struck through in the article below because they are false.

I want to delete all lines in the current file not containing the string foo:

:g/^.*?\@!foo/d

Explanation: Using the global command g (“act on range or entire file”) like :g/pattern/d applies the command d (“delete line”) to any line in the current file that matches pattern.

Since VIm generally does not support inverting RegExps (for example like sed does with the modifier !), I employ the “negative lookahead operator” @! (that has to be escaped \@!) of VIm-RegExp-syntax.

Since, in VIm RegExp syntax, look-ahead must follow something (why? I don’t know) I precede it with ^.*, but this is not enough, since it renders the obscure error E62: Nested \@ (why? I don’t know).

But it works if I make the preceeding term optional using the ? modifier. It’s a horribly inefficient RegExp, but it’s shortest to write (which is what VI-commands are all about).

And now you know that, too. :-D

P.S.: If you know a shorter version let me know -  FYI, I already know

:%!sed /foo/\!d

and it does not count – VIm onboard stuff only! ;-)

Hypnosis (5 Minutes)

Count to 600:

Note: Contains samples from Masato Hagiwara in Kiyoshi Kurosawa’s “Kyua” (Japan, 1997).

Update: YouTube “Userstyle”

I have updated my YouTube Userstyle to the latest names they have given to their BS.

You can visit the style’s entry at userstyles.org for review and installation:

See also: Original announcement (20 Nov 2013).

Hypnosis (Kei-san)

Cover art.

Cover art.

Electronic @ 120bpm:

Note: Contains samples from Masato Hagiwara in Kiyoshi Kurosawa’s “Kyua” (Japan, 1997).

Update: R2 [Mo. 3 Feb. 2014].