33

I select a block of text using Ctrl-V, but when I then type Shift-A or Shift-I, my vim editor goes into insert mode on only the location where I began the visual block mode.

For example,

Here
is 
text

I want

#Her 
#is 
#text

but I get:

#Here
is 
text
4
  • That's perfectly normal.
    – romainl
    Feb 17, 2013 at 21:23
  • I had this problem. It could be your Ctrl-V is being intercepted and transformed at the GUI level. Your terminal program might be trapping the Ctrl-V and changing it to something else before vim even sees it. For me it turns out what happened long ago I had fiddled with the Konsole shortcut keys and remapped Ctrl-V to Shift+ins for compatibility issues. To fix, I went to konsole -> settings -> configure shortcuts -> remove the remap of Ctrl-V to Shift+ins. A way to prove if this is the case is to use vim to remap a different keystroke to Ctrl-V in the vimrc to bypass the intercept. Sep 12, 2017 at 4:58
  • 4
    Same issue for me, using zsh on a Mac, and none of the answers below work. I can use Ctrl-V just fine, and often do, but Shift-i kicks me out of Visual mode and into ordinary (not multi-line) insert mode.
    – rossdavidh
    Jan 19, 2018 at 15:59
  • Make sure you do your block selection by some sort of movement (movement counts, movement to match etc). If you use a text object to highlight the block, then I observe this behaviour where it just reverts to inserting at the original cursor position.
    – Chris
    Aug 15, 2020 at 11:59

4 Answers 4

34

Make sure you exit visual block with ESC, not Ctrl C.

Also, Vim does not live update in visual block mode, you have to leave visual block mode to show the changes on other lines.

You will only see:

#Here
is 
text

After you enter visual block and insert a #, but once you leave visual block mode pressing ESC it should look like:

#Here
#is 
#text
26

Ctrl-V-> select the block -> press I -> type #

then press ESC

more detail:

:h v_b_I

you can see:

Visual-block Insert                     *v_b_I* 

With a blockwise selection, I{string}<ESC> will insert {string} at the start 
of block on every line of the block, provided that the line extends into the block. 
7
  • 10
    Note that the default vim installed with Ubuntu 14.04 (installed as vi) does not include the visualextra feature, so block insert won't work there. sudo apt-get install vim brings in a more full-featured version, on which visualextra is activated. You can check the output of vim --version to see the full list of activated features. Jul 15, 2015 at 12:49
  • 3
    esc was the key. I've been using C_c to escape insert mode. :| Dec 28, 2016 at 20:28
  • 2
    Note "wait 1 second and the inserted text will appear on every line"
    – Steve
    Sep 30, 2018 at 6:21
  • 1
    i got to press I (shift + i) step in zsh, it seems to only be only editing one line for some reason
    – Shuliyey
    May 1, 2020 at 2:59
  • 1
    ok it seems to only take in effect after i click Esc after the edit, is there anyway to have vim displaying the multi column editting change in realtime
    – Shuliyey
    May 1, 2020 at 3:05
9

For me the problem was that I was using linewise visual mode (i.e. enter visual mode by pressing V), rather than blockwise visual mode (i.e. enter visual mode by using Ctrl-v). Also note that you have to exit visual mode by using <Esc> (or equivalently by using Ctrl-[ on English keyboards) rather than by using Ctrl-c.

2
  • 1
    yes! if you see "-- VISUAL LINE --" text in the bottom line, it will not work. Use CTRL+V instead Oct 19, 2019 at 10:00
  • 1
    Me too, Vim has three visual mode -- VISUAL --,-- VISUAL LINE -- and -- VISUAL BLOCK --, <kbd>A</kbd> and <kbd>I</kbd> only for -- VISUAL BLOCK -- .
    – feng zhang
    Apr 25, 2020 at 9:29
0
rpm -qa | grep vim

vim-enhanced-7.4.160-1.el7.x86_64
vim-common-7.4.160-1.el7.x86_64
vim-filesystem-7.4.160-1.el7.x86_64

1/just remove vi and use vim instead
or
2/alias vim='vi' in your bashrc
or
3/ln -s $(which vim) $(which vim|sed 's/vim/vi/g')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.