如网页所示,有两种方法可以在HTML文件中使用tern_for_vim插件。
use tern_for_vim plugin in HTML files
这两种方法都可以工作,但都不能使js自动弹出补全菜单。
Method1:
1.vim test.html
2.:setlocal omnifunc=tern#Complete
3.To input `<C-X><C-O>` after `document.` 现在js补全弹出来了。
这种方法还存在两个问题。
1.用.vimrc编写setlocal omnifunc=tern#Complete是不可行的。
为什么?
2.如何在document.后自动弹出js补全菜单,而不是输入<C-X><C-O>
Method2:
sudo cp .vim/bundle/tern_for_vim/after/ftplugin/javascript_tern.vim .vim/bundle/tern_for_vim/after/ftplugin/html_tern.vim您应该在document.之后输入<C-X><C-O>,以便为您编辑的html文件调用js完成菜单。
在document.之后,无法自动弹出已编辑的js文件的js完成菜单。
1.如何在document.后自动弹出js补全菜单,而不是输入<C-X><C-O>?(与Method1中的第二项相同。)
发布于 2018-03-23 22:58:49
发布于 2018-03-24 02:40:32
我猜您使用的是Method 2,它使用的是<C-X><C-O>
您将需要inoremap来执行此操作,请参见:What's the meaning of 'inoremap' in vimrc
由于Tern for Vim连接到omni completion (作为https://github.com/ternjs/tern_for_vim ),因此您可以修改它的键映射,使其行为符合您的需要。
来自文档:http://vimdoc.sourceforge.net/htmldoc/insert.html#ft-javascript-omni
您可以在映射中使用,以便在键入字符并满足某些条件时使用弹出式菜单。例如,对于键入一个点:
inoremap <expr> . MayComplete()
func MayComplete()
if (can complete)
return ".\<C-X>\<C-O>"
endif
return '.'
endfunc打开vim并在命令模式下键入以下命令即可完成此操作:
:inoremap <expr> . ".\<C-X>\<C-O>"这基本上将.转换为触发<CTRL-X> <CTRL-O>的触发器
但最好将:map命令放入~/.vim/ftplugin/{filetype}_mappings.vim中。(这要求您拥有:filetype plugin on。)
这是用于一般vim键映射的:http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-(Part_1)
检查以下代码以查看其工作情况:https://imgur.com/gpvzaUt
PS :我使用Pathogen安装了Tern for Vim ( https://github.com/tpope/vim-pathogen )
我希望这能回答你的问题,或者至少能给你一个启发。
https://stackoverflow.com/questions/49294257
复制相似问题