Vim: How to insert in visual block mode?
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.
VIM Blockwise Insert
You have two primary options:
Select in block visual mode (ctrl-v), then use
I
to insert the same thing along the left side of the entire block. SimilarlyA
appends; see blockwise operators.Select the lines in normal visual (v) or visual line (V) mode, then run the same command on all of them, for example
s/^/# /
ornormal I#
. Typing:
while you have a visual selection automatically uses the visual selection as the line range (denoted by'<,'>
).
Visual block insert/append doesn't work
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.
Visual block insert in redhat vim
Solution to your updated question:
- Go between "hello" & "world" on first line
- Press Ctrl+v to enter visual block mode.
- Go down using
2j
to select that column - Press I #An uppercase
I
- Press 4 spaces to get the desired output.
- Press Esc
Here's a small demo:
How to insert after the cursor in Vim visual block mode
Just like i inserts before the cursor and a inserts after the cursor in normal mode, Shift+a inserts after the cursor in visual block mode.
Insert lines of file into multi-line selection (visual block mode) in Vim
Yes! Just highlight the numbers in visual block mode (C-v
):
31
37
14
Yank them (y
) and in normal mode place your cursor where I've put a |
symbol below:
This is the beginning of a file with several lines
Age of Person A:|; Other info...
Age of Person B: ; Other info...
Age of person C: ; Other info...
This is the end of the file.
and use the put command (p
). You'll end up with:
This is the beginning of a file with several lines
Age of Person A: 31; Other info...
Age of Person B: 37; Other info...
Age of person C: 14; Other info...
This is the end of the file.
Switch cursor position in visual block insert mode
So, based on your comment:
The column insertion is done in a single step. Do your selection (c-v), go down, go in insert mode (I), add your x and leave the insert mode with either escape
or ctrl-[
. As you quit the insert mode, the inserted text will be added on all the lines.
In any case, your cursor will go back at the beginning. If you want to bring it at the end of what has been selected, you can do it by pressing: '>
which marks the end of the last visual selection.
EDIT: After further discussion about the need, the point is to execute a column insert on a long range.
I would do 3 splits (with :sp
), I would resize (by dragging the statusbar of a window) the 2 top ones to show each one line (the beginning of the selection for one, and the end for the other), they will be used as reference.
Then, use the third one to do the actual manipulation, and as you will type/indent (at the beginning of the selection), you will see it change in one of your small splits and you can compare with the other one to indent to where you want.
Here is a screenshot to illustrate it (I wanted to indent from line 1 to 43 and I use my first split as a reference to indent everything on where "blandit" is, line 44), I use the first split to see the beginning, the second to see the end and the 3rd to actually do the whole manipulation:
Vim - Add in visual block selection
You are almost there, it's A
, not a
.
You can also use I
to prepend, see :help blockwise-operators
.
Related Topics
How to Make Block Local Variables the Default in Ruby 1.9
Can Multiple Sidekiq Instances Process The Same Queue
How to Use Coffeescript in the Views Executed on Render.Js
How to Import Using Fastercsv a Row with a Name Like "CiaráN"
How to Do Complex Querying with Logical Operations by Using Searchkick
How to Add Attribute to Nokogiri Node
Killing Process Group from Ruby Kills My Whole Computer
How to Retrieve Exif Information of an Image in Rails
How Do Open a File for Writing Only If It Doesn't Already Exist in Ruby
Rounding a Float to the Nearest Integer in Ruby
How to Daemonize Rails Rake Task on Elastic Beanstalk Start Up
Cancan Load_And_Authorize_Resource Triggers Forbidden Attributes
Rails 3. How to Explicitly Round a Number to Two Decimal Places in The Model