VIM Blockwise Insert

I would like to insert a hash at the beginning of the selected block of text in VIM (ruby comment). I selected rows in Visual Mode, but how do I perform the same operation on all rows?

+8
ruby vim
May 20 '10 at 2:59
source share
3 answers

You have two main options:

  • Select in block visualization mode (ctrl-v), then use I to insert the same on the left side of the entire block. Similarly, A adds; see block statements .

  • Select the lines in normal visual (v) or visual line (V) mode, then run the same command for all of them, for example s/^/# / or normal I# . Input : while you have a visual selection, the visual selection is automatically used as a range of lines (indicated by the symbol '<,'> ).

+13
May 20 '10 at 15:03
source share

In visual mode, run

 :'<,'>s/^/# 

In fact, '<,'> will be inserted automatically when you press :

+4
May 20, '10 at 15:06
source share

You better use this.

COMMAND MODE with a given number to see the lines

: 10.50s / ^ / # / g

The first number before the decimal is the start line and the second number after the decimal is the final line. Both are included.

+1
May 20 '10 at 15:02
source share



All Articles