VIM Blockwise Insert

ruby, vim

Solution

You have two primary options:

Select in block visual mode (ctrl-v), then use `I` to insert the same thing along the left side of the entire block. Similarly `A` appends; see blockwise operators.

Select the lines in normal visual (v) or visual line (V) mode, then run the same command on all of them, for example `s/^/# /` or `normal I#`. Typing `:` while you have a visual selection automatically uses the visual selection as the line range (denoted by `'<,'>`).

Problem

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

Original source