问题
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 <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
I've read the wikia doc and many posts such as:
- Vim: How to insert in visual block mode?
- Visual block insert/append doesn't work
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
回答1:
Solution to your updated question:
- Go between "hello" & "world" on first line
- Press Ctrl+v to enter visual block mode.
- Go down using
2jto select that column - Press I #An uppercase
I - Press 4 spaces to get the desired output.
- Press Esc
Here's a small demo:
回答2:
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.
回答3:
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
回答4:
Try :10,20s/^/ /, insert space only for line 10-20
来源:https://stackoverflow.com/questions/22237940/visual-block-insert-in-redhat-vim