Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a character at the beginning of each line in Gvim?

Tags:

vim

What the fastest way to turn this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, 

sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut 
enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit

in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa 
qui officia deserunt mollit anim id est laborum.

Into this:

> Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
>
> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim 
> ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
> ex ea commodo consequat. Duis aute irure dolor in reprehenderit
>
> in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 
> sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 
> mollit anim id est laborum.

With Gvim?

like image 212
alexchenco Avatar asked Dec 20 '22 04:12

alexchenco


2 Answers

Go to the beginning of the first line and press ctrl+v to enter in visual block.

Scroll down until the last line and then press shift+i.

Now type the text you want and then press esc.

This should do the job. :)

like image 158
Vlad Tarniceru Avatar answered Jan 14 '23 13:01

Vlad Tarniceru


One solution as already mentioned is search and replace but it forces you to think in command line mode io normal mode.

The most natural way for me is to think about how I would change one line in normal mode (I>) and apply that to the whole file by using :%norm

This would be

:%norm I>

Perhaps not the shortest possible sequence but it doesn't interrupt my train of thought to much.

like image 31
Lieven Keersmaekers Avatar answered Jan 14 '23 11:01

Lieven Keersmaekers