Vim: faster way to select blocks of text in visual mode

前端 未结 16 1959
面向向阳花
面向向阳花 2021-01-29 17:12

I have been using vim for quite some time and am aware that selecting blocks of text in visual mode is as simple as SHIFT+V and moving the arrow key up or

相关标签:
16条回答
  • 2021-01-29 17:50

    I use this with fold in indent mode :

    v open Visual mode anywhere on the block

    zaza toogle it twice

    0 讨论(0)
  • 2021-01-29 17:53

    Vim is a language. To really understand Vim, you have to know the language. Many commands are verbs, and vim also has objects and prepositions.

    V100G
    V100gg
    

    This means "select the current line up to and including line 100."

    Text objects are where a lot of the power is at. They introduce more objects with prepositions.

    Vap
    

    This means "select around the current paragraph", that is select the current paragraph and the blank line following it.

    V2ap
    

    This means "select around the current paragraph and the next paragraph."

    }V-2ap
    

    This means "go to the end of the current paragraph and then visually select it and the preceding paragraph."

    Understanding Vim as a language will help you to get the best mileage out of it.

    After you have selecting down, then you can combine with other commands:

    Vapd
    

    With the above command, you can select around a paragraph and delete it. Change the d to a y to copy or to a c to change or to a p to paste over.

    Once you get the hang of how all these commands work together, then you will eventually not need to visually select anything. Instead of visually selecting and then deleting a paragraph, you can just delete the paragraph with the dap command.

    0 讨论(0)
  • 2021-01-29 17:53

    For selecting number of lines:

    shift+v 9j - select 10 lines

    0 讨论(0)
  • 2021-01-29 17:54

    v35G will select everything from the cursor up to line 35.

    v puts you in select mode, 35 specifies the line number that you want to G go to.

    You could also use v} which will select everything up to the beginning of the next paragraph.

    0 讨论(0)
  • 2021-01-29 17:55
    G                       Goto line [count], default last line, on the first
                            non-blank character linewise.  If 'startofline' not
                            set, keep the same column.
                            G is a one of jump-motions.
    

    V35G achieves what you want

    0 讨论(0)
  • 2021-01-29 17:57

    v%

    will select the whole block.

    Play with also:

    v}, vp, vs, etc.

    See help:

    :help text-objects

    which lists the different ways to select letters, words, sentences, paragraphs, blocks, and so on.

    0 讨论(0)
提交回复
热议问题