Vim multiline editing like in sublimetext?

后端 未结 7 1088
借酒劲吻你
借酒劲吻你 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:15

    I'm not sure what vim is doing, but it is an interesting effect. The way you're describing what you want sounds more like how macros work (:help macro). Something like this would do what you want with macros (starting in normal-mode):

    1. qa: Record macro to a register.
    2. 0w: 0 goto start of line, w jump one word.
    3. i"<Esc>: Enter insert-mode, insert a " and return to normal-mode.
    4. 2e: Jump to end of second word.
    5. a"<Esc>: Append a ".
    6. jq Move to next line and end macro recording.

    Taken together: qa0wi"<Esc>2ea"<Esc>

    Now you can execute the macro with @a, repeat last macro with @@. To apply to the rest of the file, do something like 99@a which assumes you do not have more than 99 lines, macro execution will end when it reaches end of file.

    Here is how to achieve what you want with visual-block-mode (starting in normal mode):

    1. Navigate to where you want the first quote to be.
    2. Enter visual-block-mode, select the lines you want to affect, G to go to the bottom of the file.
    3. Hit I"<Esc>.
    4. Move to the next spot you want to insert a ".
    5. You want to repeat what you just did so a simple . will suffice.
    0 讨论(0)
提交回复
热议问题