ovatsug25
ovatsug25

Reputation: 8616

Vim: How to insert in visual block mode?

How can you insert when you are in visual block mode (by pressing ctrl-V) in Vim?

Upvotes: 245

Views: 261745

Answers (5)

rugby82
rugby82

Reputation: 699

if you want to add new text before or after the selected colum:

  • press ctrl+v (after placing cursor at correct column)
  • select columns
  • press shift+i
  • write your text
  • press esc
  • press "jj" (not needed in some versions)

Upvotes: 26

Nishant
Nishant

Reputation: 21934

You might also have a use case where you want to delete a block of text and replace it:

Hello World
Hello World

to

Hello Cool 
Hello Cool

You can visual block select before "W" and hit Shift+i - Type "Cool" - Hit ESC and then delete "World" by visual block selection .

Alternatively, the cooler way to do it is to just visual block select "World" in both lines. Type c for change. Now you are in the insert mode. Insert the stuff you want and hit ESC. Both gets reflected with lesser keystrokes.

Upvotes: 40

Tomás F. N.
Tomás F. N.

Reputation: 121

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 03 2023 07:45:49)

CTRL + q  - ENTER VISUAL MODE
j or k    - SELECT LINES BELOW OR ABOVE
SHIFT + i - ADD CONTENT TO THE FIRST LINE
ESC       - EXIT INSERT MODE
j         - PROPAGATE CHANGES TO THE OTHER LINES

Upvotes: 10

ovatsug25
ovatsug25

Reputation: 8616

Try this

After selecting a block of text, press Shift+i or capital I.

Lowercase i will not work.

Then type the things you want and finally to apply it to all lines, press Esc twice.




If this doesn't work...

Check if you have +visualextra enabled in your version of Vim.

You can do this by typing in :ver and scrolling through the list of features. (You might want to copy and paste it into a buffer and do incremental search because the format is odd.)

Enabling it is outside the scope of this question but I'm sure you can find it somewhere.

Upvotes: 367

dom free
dom free

Reputation: 1235

  1. press ctrl and v // start select
  2. press shift and i // then type in any text
  3. press esc esc // press esc twice

Upvotes: 78

Related Questions