Visual block insert in redhat vim

故事扮演 提交于 2019-12-22 18:25:58

问题


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:

  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:




回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!