Vim Blockwise Insert

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. Similarly A 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/^/# / or normal 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:

  1. Go between "hello" & "world" on first line
  2. Press Ctrl+v to enter visual block mode.
  3. Go down using 2j to select that column
  4. Press I #An uppercase I
  5. Press 4 spaces to get the desired output.
  6. Press Esc

Here's a small demo:

demo gif

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:

split

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



Leave a reply



Submit