2011-10-02

Deleting lines in Vim

QUESTION

In Vim, turn the following:

function add(x, y)
    return x + y
endfunc

function subtract(x, y)
    return x - y
endfunc

function multiple(x, y)
    return x * y
endfunc

into:

function add(x, y)
function subtract(x, y)
function multiple(x, y)

ANSWER

:g!/function/d

EXPLANATION

: - go into command mode
g - search the entire file
! - negate the following search pattern
/function/ - look for the word "function"
d - delete the line containing the selection


No comments: