简体   繁体   中英

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

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?

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. :)

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.

我不知道gvim,但是在vim中你可以标记顶部和底部的行,分别用a和b说,然后执行以下命令:

:'a,'bs/^/> /gc

Well,you no necessary to use the visual mode to accomplish this task. Using the global replace command is super easy.

try execute this command and press enter:

:%s/^/>/g

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM