Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a word at the beginning of multiple lines in vim?

Tags:

vim

In Vim,

How do i add a word at the beginning of all lines? Also how do i add it at end?

Eg.. If i have

A
B
C
D

I want to make it to

int A =
int B = 

etc..

like image 512
excray Avatar asked Jan 13 '11 15:01

excray


1 Answers

use visual block mode (Ctrl-v) to select the column you want, and then hit I, type the characters you want, and then hit Esc

So in this case, you'd put your cursor on A, hit Ctrl-v, go down to D, hit I and type int (it'll only appear on the first line while you type it), and then hit Esc at which point it'll apply that insert to all visually selected portions.

This works for anywhere in the document, beginning of line or end of line.

:he v_b_I for more info on Visual Block Insert

like image 90
Daniel DiPaolo Avatar answered Oct 13 '22 04:10

Daniel DiPaolo