Vim multiline editing like in sublimetext?

后端 未结 7 1103
借酒劲吻你
借酒劲吻你 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 17:52

    Do yourself a favor by dropping the Windows compatibility layer.

    The normal shortcut for entering Visual-Block mode is .

    Others have dealt with recording macros, here are a few other ideas:

    Using only visual-block mode.

    1. Put the cursor on the second word:

      asd |a|sd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      
    2. Hit to enter visual-block mode and expand your selection toward the bottom:

      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      asd [a]sd asd asd asd;
      
    3. Hit I" to obtain:

      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      
    4. Put the cursor on the last char of the third word:

      asd "asd as|d| asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      asd "asd asd asd asd;
      
    5. Hit to enter visual-block mode and expand your selection toward the bottom:

      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      asd "asd as[d] asd asd;
      
    6. Hit A" to obtain:

      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      

    With visual-block mode and Surround.vim.

    1. Put the cursor on the second word:

      asd |a|sd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      asd asd asd asd asd;
      
    2. Hit to enter visual-block mode and expand your selection toward the bottom and the right:

      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      asd [asd asd] asd asd;
      
    3. Hit S" to surround your selection with ":

      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      

    With visual-line mode and :normal.

    1. Hit V to select the whole line and expand it toward the bottom:

      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      [asd asd asd asd asd;]
      
    2. Execute this command: :'<,'>norm ^wi"eea" to obtain:

      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      asd "asd asd" asd asd;
      
      • :norm[al] allows you to execute normal mode commands on a range of lines (the '<,'> part is added automatically by Vim and means "act on the selected area")

      • ^ puts the cursor on the first char of the line

      • w moves to the next word

      • i" inserts a " before the cursor

      • is Vim's way to input a control character in this context, here it's used to exit insert mode

      • ee moves to the end of the next word

      • a" appends a " after the cursor

      • executes the command

      Using Surround.vim, the command above becomes

      :'<,'>norm ^wvees"
      

提交回复
热议问题