<p>In <a href="http://en.wikipedia.org/wiki/Vim_%28text_editor%29" rel="noreferrer">Vim</a>, how do I  insert characters at the beginning of each line in a selection?</p>

<p>For instance,  I want to comment out a block of code by prepending <code>//</code> at the beginning of each line assuming my language's comment system doesn't allow block commenting like <code>/* */</code>.  How would I do this?</p>

This replaces the beginning of
each line
with "//":
```
```
:%s!^!//!
```
```
This replaces the beginning of
each selected line
(use visual mode to select) with "//":
```
```
:'<,'>s!^!//!
```
```
Note
that
```
gv
```
(in normal mode) restores the last visual selection, this comes in handy from time to time.