Selecting entire function definition in Vim

前端 未结 11 705
醉话见心
醉话见心 2020-12-07 14:14

I\'ve been trying Vim for any text editing work for almost a week now. I want to know the fastest way to select a C function definition.

For example, if I have a fun

11条回答
  •  醉酒成梦
    2020-12-07 14:21

    To delete an entire function, including its definition, such as:

    function tick() {
            // ... 
    }
    
    • Move to the line with the function name.
    • Move the cursor to the opening brace, f{ should do it, or simply $.
    • Press V%d (Visual line, move to matching pair, delete)

    If your functions look like this:

    function tick() 
    {
            // ... 
    }
    
    • Move to the line with the function name.
    • Press J (join the current line with line bellow. This also puts your cursor at the last character on the resulting line, {, just the one we need for the next command.)
    • Press V%d (Visual line, move to matching pair, delete.)

    or

    • Move to the line with the function name.
    • Press V[Down]%d (Visual line, move one line down, move to matching pair, delete.)

提交回复
热议问题