Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertical editing in vim - replacing text

Tags:

vim

If I want type the same text in many lines I use: ctrl-v, then I, typing, esc

so I can make fast changes from:

aaa
bbb
ccc
ddd
...

to:

123aaa
123bbb
123ccc
123ddd
...

but it doesnt work if I use del while typing. and i must do column replace in 2 steps: removing unwanted characters from column (ctrl-v + x), then typing like above.

is it possible to improve editing and do it in single operation? sth like:

aaa
bbb
ccc
ddd
...

to:

123aa
123bb
123cc
123dd
...
like image 240
Sławomir Lenart Avatar asked Mar 19 '14 11:03

Sławomir Lenart


People also ask

How do you replace a word in Vim?

The simplest way to perform a search and replace in Vim editor is using the slash and dot method. We can use the slash to search for a word, and then use the dot to replace it. This will highlight the first occurrence of the word “article”, and we can press the Enter key to jump to it.

How do I select vertically in Vim?

ctrl+shift+v is visual block. So just press ctrl+shift+v and then use cursor keys to select what you want.

How do you change multiple words in Vim?

Change and repeat Search for text using / or for a word using * . In normal mode, type cgn (change the next search hit) then immediately type the replacement. Press Esc to finish. From normal mode, search for the next occurrence that you want to replace ( n ) and press . to repeat the last change.


1 Answers

You can select the first column and do c123:

[a]aa
[b]bb
[c]cc
[d]dd

c123<Esc>

123aa
123bb
123cc
123dd

In visual-block mode, s is equivalent to c. You can also use d and x to cut the selection, rx to replace every character in the selection with x and of course y to yank the whole block. You can also use p to paste but you need to be careful with what you paste.

like image 162
romainl Avatar answered Oct 07 '22 16:10

romainl