Can you grab or delete between parentheses in vi/vim?

前端 未结 7 980
难免孤独
难免孤独 2020-12-07 07:43

Given this line of code in C:

printf(\"%3.0f\\t%6.1f\\n\", fahr, ((5.0/9.0) * (fahr-32)));

相关标签:
7条回答
  • 2020-12-07 08:37

    To delete all that is inside a pair of parentheses, you can always issue di( and its derivatives.

    Note :

    As @porglezomb suggested in his comment, you can use a ("along with") instead of i ("inside") to include the parentheses. So, using da( deletes everything inside ( and ) including ( and ).

    Deleting text inside the immediate outer pair of parentheses :

    So, for this line of code

    printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
                                    ^       ^
                                    |       |
                                     \_______\___---> Cursor range
    

    assuming that your cursor is inside the above mentioned cursor range, you can issue the following commands :

    di(   --> Deletes '5.0/9.0'
    ci(   --> Substitutes '5.0/9.0'
    yi(   --> Yanks '5.0/9.0'
    

    Deleting text inside the n-th outer pair of parentheses :

    To grab everything inside the n-th outer pair of parentheses, just add n before the above command. So, with the same cursor position as above,

    2di(   --> Deletes '(5.0/9.0) * (fahr-32)'
    2ci(   --> Substitutes '(5.0/9.0) * (fahr-32)'
    2yi(   --> Yanks '(5.0/9.0) * (fahr-32)'
    
    3di(   --> Deletes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
    3ci(   --> Substitutes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
    3yi(   --> Yanks '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
    
    0 讨论(0)
提交回复
热议问题