Vim multiline editing like in sublimetext?

后端 未结 7 1102
借酒劲吻你
借酒劲吻你 2021-01-29 17:15

I started to use gvim, and I can\'t quite understand how the multiline edit works in gvim.

For example:

Original text:

asd asd asd asd asd;
asd a         


        
7条回答
  •  感情败类
    2021-01-29 18:14

    My solution is to use these 2 mappings:

    map n 0qq
    map m q:'<,'>-1normal!@q
    

    How to use them:

    1. Select your lines. If I want to select the next 12 lines I just press V12j
    2. Press n
    3. Make your changes to the line
    4. Make sure you're in normal mode and then press m

    To make another edit you don't need to make the selection again. Just press n, make your edit and press m to apply.


    How this works:

    • 0qq Exit the visual selection, go to the beginning of the line and start recording a macro.

    • q Stop recording the macro.

    • :'<,'>-1normal!@q From the start of the visual selection to the line before the end, play the macro on each line.

    • Go back down to the last line.


    You can also just map the same key but for different modes:

    vmap m 0qq
    nmap m q:'<,'>-1normal!@q
    

    Although this messes up your ability to make another edit. You'll have to re-select your lines.

提交回复
热议问题