Vim: Repeat previous motion?

前端 未结 4 924
梦毁少年i
梦毁少年i 2021-02-01 12:15

Let\'s say that I\'m in visual mode, and I type \"aw\" to extend the visual area to include the next word. I\'d like to then include the next couple of words. Is there a singl

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 13:02

    NO PLUGINS use ;.

    Here's a detailed example:

    int function1(){
       some code here;
       ...
       ...
       return 0;
    }
    
    int function2(){
       some code here;
       ...
       ...
       return 0;
    }
    

    Now let's say you want to rewrite the part inside {} for function1 and function2.

    • Place your cursor somewhere inside the {}
    • From Normal Mode (ESC or ctrl+c), press di} (for "delete" "inner" "{")
    • Now you've deleted everything in the function
    • Now bring your cursor inside the {} of function2
    • Press ;.

    For visual mode, I think macros is your only option (maybe overkill for aw)

    • To start recording a macro, press q + q (that last q can be any letter. It's where you macro will be saved)
    • ... do the actions you want to repeat ...
    • Press q again to stop recording

    To replay these actions (even in visual mode):

    • @q (or whatever letter you saved it to)

    To replay the actions 99 times:

    • 99@q (or whatever letter you saved it to)

提交回复
热议问题