2

I'm really fond of this idea of using Ctrl-V (Ctrl-Q in windows) to modify a visual block. The technique is explained here: In Vim how do I effectively insert the same characters across multiple lines?

For some reason, this is not working for me in VIM 7.2.411.

I press Ctrl-V, it says visual block, and I press J several times to expand my selection. Then I press Shift-I to insert, place my text, and when I press Esc, it has only modified the top line of the selection. I've had a hard time figuring out why this isn't working on my linux box. The same technique works great for gvim in windows.

What might be preventing this from working, or what should I try differently?

4

3 に答える 3

4

The source of the problem was lack of compiled support (thanks to my shared hosting provider). For others who are having a similar problem, check vim for the +visualextra option. You can check from normal mode with:

:echo has('visualextra')

It will return a "1" if it does. Otherwise you can look using:

:version

Or by invoking the --version option from the commandline:

vim --version | grep visualextra
于 2013-03-09T19:43:02.980 に答える
3

It may be as simple as not having the right package installed. Visual block mode is not included in vim-minimal which is often the default version of vi. If you do this:

rpm -qa | grep vim

and you see vim-minimal but not vim-enhanced, then you have to install vim-enhanced. That will get you visual block mode as well as many other additional features.

于 2014-04-01T20:19:59.797 に答える
2

The behavior you describe with gvim on windows is quite unexpected. I would expect the inserted text to appear only before the first line. If you do want to insert a string before all the lines of the currently selected visual block, the natural thing to do is:

:s/^/inserted text

(Note that when you type :, vim will automatically set the addresses with :'<,'>, so the actual command will be :'<,'>s/^/inserted text)

于 2013-03-09T05:40:06.353 に答える