Visual block insert/append doesn't work
Asked Answered
F

5

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
Freese answered 17/2, 2013 at 20:53 Comment(4)
That's perfectly normal.Testy
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.Kirkland
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.Bugger
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.Blacking
H
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. 
Hescock answered 17/2, 2013 at 20:56 Comment(7)
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.Immolation
esc was the key. I've been using C_c to escape insert mode. :|Eohippus
Note "wait 1 second and the inserted text will appear on every line"Octarchy
i got to press I (shift + i) step in zsh, it seems to only be only editing one line for some reasonSurvival
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 realtimeSurvival
NOTE: 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 rather than doing your S-I insert on each line, or your S-A append. I now use /^$<enter-key>k to match until the next blank line (the k is needed, or else your insert/append ends up on the blank line also.Blacking
Also, the convenient <S-v>} to select to the next blank line fails as well, as using ap or ipBlacking
L
36

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
Languorous answered 17/2, 2013 at 20:56 Comment(0)
H
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. 
Hescock answered 17/2, 2013 at 20:56 Comment(7)
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.Immolation
esc was the key. I've been using C_c to escape insert mode. :|Eohippus
Note "wait 1 second and the inserted text will appear on every line"Octarchy
i got to press I (shift + i) step in zsh, it seems to only be only editing one line for some reasonSurvival
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 realtimeSurvival
NOTE: 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 rather than doing your S-I insert on each line, or your S-A append. I now use /^$<enter-key>k to match until the next blank line (the k is needed, or else your insert/append ends up on the blank line also.Blacking
Also, the convenient <S-v>} to select to the next blank line fails as well, as using ap or ipBlacking
M
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.

Maxima answered 23/6, 2018 at 18:16 Comment(2)
yes! if you see "-- VISUAL LINE --" text in the bottom line, it will not work. Use CTRL+V insteadRuddock
Me too, Vim has three visual mode -- VISUAL --,-- VISUAL LINE -- and -- VISUAL BLOCK --, <kbd>A</kbd> and <kbd>I</kbd> only for -- VISUAL BLOCK -- .Superstitious
S
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')
Slush answered 14/12, 2014 at 11:48 Comment(0)
N
0

I had the exact same issue and I'm not sure if it's because I'm on Mac OSX. I thought I needed to hit Esc twice. However, once you hit ESC it takes a second for it to place all the characters.

In the example below I ran the following commands:

Ctrl + v
6
j
Shift + i
#
space
Esc

Here's a screen recording of how it looks:

vim visual insert

Neukam answered 14/3 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.