Quantcast
Channel: Commands tagged vim sorted by votes
Viewing all articles
Browse latest Browse all 51

Delete all empty lines from a file with vim

$
0
0
$ ggqqqqq/^$dd@qq@q

Here's the other way of doing it in vim: setting a recursive macro. 'gg' brings you to the top of the buffer, 'qqq' clears the 'q' macro, 'qq' starts recording a macro called 'q', '/^$' moves the cursor to the next empty line, 'dd' deletes the line that the cursor is on, '@q' calls the 'q' macro (currently empty because of 'qqq'), and 'q' stops recording the macro. '@q' calls the macro.

It will run until it cannot find another blank line, at which point it will throw up an error and cease.

While this is longer than the regex, you can use it without having to move your thoughts from 'vim-mode' to 'regex-mode'.

commandlinefu.com

Diff your entire server config at ScriptRock.com


Viewing all articles
Browse latest Browse all 51

Trending Articles