1

I want to select multiple lines in vim and whatever I type should be written on those lines.

It is easy to do in Notepad++ using shift-alt to select the cursor points and start typing.

For eg.

 17 #define M_SPI_BASE 48098000 18 #define SPI2_BASE 4809A000 19 #define SPI3_BASE 0x480B8000 20 #define SPI4_BASE 0x480BA000 

As in line numbers 19 and 20, I want to add 0x in front of the addresses 48098000 & 4809A000 in line 17 & 18 to get 0x48098000 & 0x4809A000 respectively.

I want to select my cursor at two different points i.e., before 48098000 & 4809A000 and type 0x.

How do I do it in vim?

1 Answer 1

4

Look into Visual Blockmode

With your cursor before 48098000 you can use following sequence

ctrl+vjI0xEsc

What might trip you up is that the changes to other rows are only made after leaving visual blockmode, not while typing them.

Breakdown:

  • ctrl+v Start Visual mode Blockwise
  • j Select downwards
  • I Start insert
  • 0x Add text
  • Esc Leave Visual mode. Vim will add the text you've typed to the selection.
Sign up to request clarification or add additional context in comments.

3 Comments

Much of the little vim-fu I have mastered to date comes from those little nuggets of gold. The book is an eye opener. Very much recommend it.
That's great! Is there a way to post a question on vim to you directly?
@SJMP - If it's possibly remotely interesting to others, feel free to post another question here on SO and no doubt it will get picked up in no time. I'm flabbergasted I even got a chance to answer this one :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.