Using VIm’s “:v” 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!

Text-Console Barchart of Storage Utilization

Written as a Bourne Shell-Script that invokes a Perl one-liner:

LC_ALL=C df -kPT | perl -ane '!/(^Filesystem|tmpfs)/ && do {
   printf("%-33s: %s\n", $F[0], "*" x int((`tput cols`-35) * $F[3] / $F[2]))
}'

 

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

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! 😉

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

WordPress: Eigene Übersetzungen in Thematic-Child-Themes

Ich habe einige deutschsprachige Textbausteine in meinem Thematic-Child-Theme “linuxfoo” angepasst. Dazu benutze ich eine Datei mit eigenen Übersetzungen auf Basis der “de_DE.po” in “Thematic” selbst und übersetze diese mit dem Gettext-Werkzeug “msgfmt”. Das Verfahren wird nachfolgend im Einzelnen beschrieben.

Read More »

Self-Hosted Webfonts: Origin Considerations

Regarding my previous article, “Self-Hosted Webfonts“, various sources such as [1] suggest that additional measures should be taken so that unrelated web presences can not utilize the hosted fonts by simply referencing them on their own pages (thus “borrowing” traffic by using a font file that someone else hosts).

Read More »

Self-hosted Webfonts: An Example

For aesthetic reasons, because I consider support widespread enough and also as an exercise I have integrated several webfonts with the new appearance of this website. I think it looks OK, and it works OK in modern browsers.

Read More »

 Ein “Userstyle” für die YouTube-Startseite

In weiteren Nachrichten: So sieht, Stand heute, die Startseite von youtube Deutschland aus:

Youtube Screenshot

Screenshot von youtube.de am 20.11.2013

Und so sieht sie aus, wenn ich meinen Stylish!-Userstyle “Uncluttering YouTube” geladen habe:

Startseite von youtube Deutschland, Stand 20.11.2013 mit meinem Stylish!-Userstyle "unclutter youtube"

Startseite von youtube Deutschland, Stand 20.11.2013 mit meinem Stylish!-Userstyle “unclutter youtube”

Read More »