Quickest way to change a pair of parenthesis to brackets in vim

后端 未结 6 1131
野的像风
野的像风 2020-12-30 02:00

I am new to vim and in the process of discovering tons of interesting things that one can using this powerful editor.

One particular thing that I need to do very fr

6条回答
  •  Happy的楠姐
    2020-12-30 02:53

    Based on a few of the SO's around this matter (see my comment in the @mb14 answer here), I was thinking of muscle-memorizing something like this:

    di(a[]P
    

    but what I really wanted to do was this:

    di(c%[]P
    

    You will see that you cannot do that because the c puts the () brackets into your 0 register and therefore you actually need to do this:

    di("_c%[]P
    

    or (I was also trying out a 'yank' approach and came up with) this:

    yi(ca([]"0P
    

    Okay, neither is too bad, but it occurred to me that this is going to all go much better if I map c to "_c so that I have a real delete and can do this:

    di(\c%[]P
    

    or this:

    yi(\ca([]P
    

    Both are pretty close to what I wanted to do, and the thought process has given me one of the most valuable lines in my $MYVIMRC:

    noremap c "_c
    

提交回复
热议问题