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

前端 未结 16 1958
面向向阳花
面向向阳花 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:41

    You can always just use antecedent numbers to repeat actions:

    • In visual mode, type 35 and the cursor will move down 35 times, selecting the next 35 lines
    • In normal mode:
      • delete 35 lines 35dd
      • paste 35 times 35p
      • undo 35 changes 35u
      • etc.
    0 讨论(0)
  • 2021-01-29 17:41

    You can press vi} to select the block surrounded with {} brackets where your cursor is currently located.

    It doesn't really matter where you are inside that block (just make sure you are in the outermost one). Also you can change { to anything that has a pair like ) or ].

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

    For selecting all in visual: Type Esc to be sure yor are in normal mode

    :0 
    

    type ENTER to go to the beginning of file

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

    } means move cursor to next paragraph. so, use v} to select entire paragraph.

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

    In addition to what others have said, you can also expand your selection using pattern searches.

    For example, v/foo will select from your current position to the next instance of "foo." If you actually wanted to expand to the next instance of "foo," on line 35, for example, just press n to expand selection to the next instance, and so on.

    update

    I don't often do it, but I know that some people use marks extensively to make visual selections. For example, if I'm on line 5 and I want to select to line 35, I might press ma to place mark a on line 5, then :35 to move to line 35. Shift + v to enter linewise visual mode, and finally `a to select back to mark a.

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

    It could come in handy to know:

    In order to select the same ammount of lines for example use 1v You should have done some modification to be able to use 1v, blockwise or linewise.

    Today I saw this amazing tip from here:

     :5mark < | 10mark > | normal gvV
     :5mark < | 10mark > | normal gv
    

    You can also reset the visual block boundaries doing so:

    m< .......... sets the visual mode start point
    m> .......... sets the visual mode end point
    
    0 讨论(0)
提交回复
热议问题