简体   繁体   English

在某些字符上显示Vim omnicomplete而不是Ctrl-X Ctrl-O?

[英]Show Vim omnicomplete on certain characters instead of Ctrl-X Ctrl-O?

In Vim 7, Ctrl-X Ctrl-O shows a list of possible values but I find this sequence of keys to be too long when I frequently use the autocomplete feature. 在Vim 7中,Ctrl-X Ctrl-O显示了可能值的列表,但是当我经常使用自动完成功能时,我发现这个键序列太长。 For instance, in an HTML file, I'd like to see the list automatically popup after I type a < followed by one or two letters. 例如,在HTML文件中,我想在输入<后跟一个或两个字母后自动弹出列表。 In a CSS file, I'd like to see the list after I hit the ":" key. 在CSS文件中,我想在点击“:”键后看到列表。 Is there a way to set this up? 有没有办法设置它?

To activate the omnicompletion on typing a ":" you can use the following mapping. 要激活键入“:”的omnicompletion,您可以使用以下映射。

imap : :<c-x><c-o>

The disadvantage is that each time you press ":" omnicompletion will be activated, even when typing ":" in comments or in any other context in which you do not want omnicompletion. 缺点是每次按下“:”即使在评论中或在您不想要omnicompletion的任何其他上下文中键入“:”,也会激活omnicompletion。

I have mapped ctrl-space to active omnicompletion: 我已将ctrl-space映射到活动的omnicompletion:

imap <c-space> <c-x><c-o>

This gives me the choice to activate omni whenever I need it. 这使我可以选择在需要时激活omni。

Another alternative that I found easier is just to press tab two times when you want autocomplete, and one time for regular tab. 我发现的另一种替代方法是在需要自动完成时按Tab键两次,对常规选项卡按一次。 Add the following line to your ~/.vimrc 将以下行添加到〜/ .vimrc中

imap <tab><tab> <c-x><c-o>

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

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