简体   繁体   English

在视觉块之前无法在vim中运行

[英]prepend to visual block not working in vim

I'm really fond of this idea of using Ctrl - V ( Ctrl - Q in windows) to modify a visual block. 我真的很喜欢使用Ctrl - V (在Windows中为Ctrl - Q )修改可视块的想法。 The technique is explained here: In Vim how do I effectively insert the same characters across multiple lines? 该技术的解释如下: 在Vim中,如何有效地在多行中插入相同的字符?

For some reason, this is not working for me in VIM 7.2.411. 由于某些原因,这在VIM 7.2.411中对我不起作用。

I press Ctrl - V , it says visual block, and I press J several times to expand my selection. 我按Ctrl - V ,它显示可视块,然后按J几次以扩展选择范围。 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. 然后按Shift- 插入并放置文本,然后按Esc ,它仅修改了所选内容的第一行。 I've had a hard time figuring out why this isn't working on my linux box. 我很难弄清楚为什么这在我的Linux机器上不起作用。 The same technique works great for gvim in windows. 相同的技术对Windows中的gvim很有用。

What might be preventing this from working, or what should I try differently? 是什么阻止了此工作,或者我应该尝试其他方法吗?

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. 对于其他有类似问题的人,请检查vim的+ visualextra选项。 You can check from normal mode with: 您可以通过以下方式从正常模式进行检查:

:echo has('visualextra')

It will return a "1" if it does. 如果返回,它将返回“ 1”。 Otherwise you can look using: 否则,您可以使用:

:version

Or by invoking the --version option from the commandline: 或者通过从命令行调用--version选项:

vim --version | grep visualextra

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. vim-minimal不包括可视块模式,后者通常是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 . 并且您看到vim-minimal而不是vim-enhanced ,那么您必须安装vim-enhanced That will get you visual block mode as well as many other additional features. 这将为您提供可视块模式以及许多其他附加功能。

The behavior you describe with gvim on windows is quite unexpected. 您在Windows上用gvim描述的行为是非常意外的。 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 ) (注意,当您输入: ,vim会自动使用:'<,'>设置地址,因此实际的命令将是:'<,'>s/^/inserted text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM