How can you insert when you are in visual block mode (by pressing ctrl-V) in Vim?
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.
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. @TylerCollier This may be the same issue on your CentOS install too: check the output of vim --version
to see the full list of activated features. –
Clingy i
and a
are used to extends the selection to text objects, read my answer to this question or type :help visual-operators
. –
Cystitis r
(great for ascii art) –
Blew - press ctrl and v // start select
- press shift and i // then type in any text
- press esc esc // press esc twice
ctrl + v
, you can press j
to quickly select line(s) below the current position, or press k
to quickly select line(s) above the current position. You can also use the shift
key with the up
or down
errors to do the selection. –
Sym i
, I'm amazed. I've been using :normal iINPUT<CR>
to input at the beginning of lines. Thanks a bunch for this! –
Inclose You might also have a use case where you want to delete a block of text and replace it .
Like this
Hello World
Hello World
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.
Hello Cool
Hello Cool
ESC
then all the marked line will show the char which you type in. –
Sapotaceous if you want to add new text before or after the selected colum:
- press ctrl+v
- select columns
- press shift+i
- write your text
- press esc
- press "jj"
jj
to propagate the changes to all lines below was the last bit I was missing! –
Formalism jj
is a killer! –
Hudnall jj
? I could not manage to find anything about it and seems unnecessary to me. 🤔 –
Vacuva Visual Block
mode. –
Birchard 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
© 2022 - 2024 — McMap. All rights reserved.