The Pug Automatic

Remove debug code with Vim's :global

Written December 16, 2014. Tagged Vim.

Say you have this file open in Vim:


console.log("about to do two");
console.log("did two");


console.log("about to do four");
console.log("did four");

The logging helped you figure out an issue and now you want to be rid of the console.log lines.

There's (not surprisingly) a quick way to do that in Vim:


Any line matching the Vim regular expression /log/ will be removed.

More generally, :g[lobal] runs the given Ex command on the matching lines. In this case, the command is :d[elete].

For more details, see :help :g.

I've only used this to remove lines, but it has all sorts of applications.