gerrytan
gerrytan

Reputation: 41143

Visual block insert in redhat vim

My ec2 server came with redhat vim:

[ec2-user@****** ~]$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul  7 2012 08:03:48)
Included patches: 1-411
Modified by <[email protected]>
Compiled by <[email protected]>

I've read the wikia doc and many posts such as:

All of the guide told me to do Ctrl+V, select the area, then Shift+i, type the character to be inserted, and ESC. This doesn't work for me.

I can however do :s/^/\ and this will insert a space in front of each line, but how can I insert it in somewhere in the middle?

For example, I want to insert several spaces to turn

hello world
a cute cat
milky way

into

hello     world
a cut     e cat
milky     way

In one visual block operation

Upvotes: 2

Views: 1313

Answers (4)

Amit
Amit

Reputation: 20516

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

Upvotes: 4

user3021843
user3021843

Reputation: 454

If you are looking for a regex style answer try (matches what Visual-Block mode would have done):

:%s;\v^(.{5})(.*);\1    \2;g

To match your expected output:

:%s;\v^(.{5})\s*(.*);\1    \2;g

If you need this done only on lines 1 through 3:

:1,3s;\v^(.{5})(.*);\1    \2;g

Upvotes: 1

Brett Y
Brett Y

Reputation: 7688

Visual-block Insert is what you are trying to do with Shift+i. It is a blockwise operator

:h blockwise-operators

Blockwise operators are not available when vim is compiled without the +visualextra feature.

To check if you have this feature

:version

If you do not, then you may have to use the methods suggested in the other answers or, get another version of vim.

Upvotes: 1

Tim Green
Tim Green

Reputation: 3649

Try :10,20s/^/ /, insert space only for line 10-20

Upvotes: 0

Related Questions