在vim中进行可视化块编辑

18

我参考了这个帖子来使用vim中的块编辑。但是当我在选择块后按下Ic键时,vim进入正常的编辑模式,就像我按下了i键一样。我还发现,在选择块时,我可以使用x键删除块中的字符。

按下I之前:

enter image description here

按下 I 后:

enter image description here

如何阻止用户输入字符?

从以下版本信息开始,“+visualextra”已启用。

> $ vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2
> 2014 19:39:47) Included patches: 1-52 Modified by
> pkg-vim-maintainers@lists.alioth.debian.org Compiled by buildd@ Huge
> version with GTK2-GNOME GUI.  Features included (+) or not (-):
> +acl             +farsi           +mouse_netterm   +syntax
> +arabic          +file_in_path    +mouse_sgr       +tag_binary
> +autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
> +balloon_eval    +float           +mouse_urxvt     -tag_any_white
> +browse          +folding         +mouse_xterm     +tcl
> ++builtin_terms  -footer          +multi_byte      +terminfo
> +byte_offset     +fork()          +multi_lang      +termresponse
> +cindent         +gettext         -mzscheme        +textobjects
> +clientserver    -hangul_input    +netbeans_intg   +title
> +clipboard       +iconv           +path_extra      +toolbar
> +cmdline_compl   +insert_expand   +perl            +user_commands
> +cmdline_hist    +jumplist        +persistent_undo +vertsplit
> +cmdline_info    +keymap          +postscript      +virtualedit
> +comments        +langmap         +printer         +visual
> +conceal         +libcall         +profile         +visualextra
> +cryptv          +linebreak       +python          +viminfo
> +cscope          +lispindent      -python3         +vreplace
> +cursorbind      +listcmds        +quickfix        +wildignore
> +cursorshape     +localmap        +reltime         +wildmenu
> +dialog_con_gui  +lua             +rightleft       +windows
> +diff            +menu            +ruby            +writebackup
> +digraphs        +mksession       +scrollbind      +X11
> +dnd             +modify_fname    +signs           -xfontset
> -ebcdic          +mouse           +smartindent     +xim
> +emacs_tags      +mouseshape      -sniff           +xsmp_interact
> +eval            +mouse_dec       +startuptime     +xterm_clipboard
> +ex_extra        +mouse_gpm       +statusline      -xterm_save
> +extra_search    -mouse_jsbterm   -sun_workshop    +xpm    system vimrc file: "$VIM/vimrc"
>      user vimrc file: "$HOME/.vimrc"  2nd user vimrc file: "~/.vim/vimrc"
>       user exrc file: "$HOME/.exrc"   system gvimrc file: "$VIM/gvimrc"
>     user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc"
>     system menu file: "$VIMRUNTIME/menu.vim"   fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H
> -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz   -pthread -DORBIT2=1 -D_REENTRANT -I/usr/include/libgnomeui-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/gtk-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/x86_64-linux-gnu/gnome-vfs-2.0/include -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/cairo -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/libpng12     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.6  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1 Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype     -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lfreetype -lgconf-2 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib

3
你读过:help v_b_I吗?更改将在按下 <ESC> 后应用:I{string}<ESC> - Ruslan Osmanov
4个回答

23
在 vim 的可视块模式中,按下 I 键后,vim 似乎已经进入插入模式。但是当你退出插入模式并再次回到正常模式时,你会发现在整个选定的块中所按下的键已经生效。
你可以在这个链接中看到演示。

10

可视块模式

在选定区域之前插入文本

步骤1:使用以下操作创建您的可视块选择:

<C-v>{motion}

第二步,使用 I 进入插入模式:

I

步骤三,插入您想要的内容:

foo

第四步,离开插入模式:

<Esc>

在所选内容之后插入文本

第2步,使用A进入插入模式:

A

更改所选内容

第二步,使用c切换到插入模式并输入:

c

将所选内容替换为相同字符

步骤2,按下r

r

步骤3,按下所需的键:

-

下次再努力一点。


1
<C-v>是什么? - aateeque
2
@aateeque 按下键盘 Ctr+V - czerny

6
我刚刚在这里实施了sid-m的答案,这是结果。因为有很少的用户也遇到了这个问题。
按下 I 后:

enter image description here

输入了aaa:(不要被状态误导,这与在此处按i进行普通插入相同)

enter image description here

输入了 Esc 键。

enter image description here


3

以下方法适用于我: VIM - Vi IMproved 7.4 (2013年8月10日, 编译于2019年6月14日10:42:24)

  1. 进入可视块模式 CTRL + v
  2. 选择字符(我要删除一些列中的#号,所以我选择了#)
  3. Shift + i,即 I
  4. Shift + ;,即 :

像平常一样运行任何命令,但只对选定的块添加 \%V

  1. %s/\%V#//g

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接