【问题标题】:How to call js completion in html file instead of js file?如何在 html 文件而不是 js 文件中调用 js 完成?
【发布时间】:2018-08-20 14:48:24
【问题描述】:

我已经通过这种方式安装了 tern_for_vim 和 YouCompleteMe 来完成 js。

1个安装节点

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source ~/.nvm/nvm.sh
nvm install node

2 安装 tern_for_vim

$ cd ~/.vim/bundle
git clone https://github.com/marijnh/tern_for_vim

3 安装 YouCompleteMe

cd ~/.vim/bundle/YouCompleteMe
$ ./install.sh --clang-completer --tern-completer

4 编辑.tern-project

vim  .tern-project  
{
    "libs": [
        "browser",
        "underscore",
        "jquery"
    ],
    "plugins": {
        "node": {}
    }
}

现在到 vim test.js。
在test.js文件中输入document.后弹出js补全。

然后到 vim test.html
在test.html文件中输入document.后没有js完成弹出。
如何解决?

【问题讨论】:

    标签: javascript vim autocomplete


    【解决方案1】:

    不幸的是,这不是 tern 官方支持的。您可以在已关闭的问题中看到响应

    https://github.com/ternjs/tern_for_vim/issues/170

    因为没有实现分离 HTML 和脚本的解析逻辑。如果您想尝试一下,这可以作为一个插件来完成,但它超出了此存储库的范围。

    但是关于 SO 的另一个帖子可能会对您有所帮助

    Using tern_for_vim plugin in HTML files

    所以最好是通过 JS 文件将你的代码包含在 html 中,然后编辑 JS 文件。否则看看其他一些插件/IDE环境。我也会探索以下选项

    https://github.com/Shougo/deoplete.nvim#install

    【讨论】:

      【解决方案2】:

      我不熟悉用于 js 补全的 tern_for_vim 和 YouCompleteMe,但是您始终可以使用 vim 内置的全功能补全。

      如果添加:

      filetype on
      filetype plugin on
      set omnifunc=syntaxcomplete#Complete
      

      到您的 vimrc 文件,然后您可以在 vim 中使用 :set filetype=javascript 手动将 html 文件的文件类型设置为 javascript。 之后,在插入模式下,您可以使用 <C-x> 后跟 <C-o> 来访问特定于 JavaScript 语言的全向补全。

      然后,生成的完成菜单可以通过标准的<C-p> 向上和<C-n> 向下热键导航。

      这一点以及其他一些内置完成功能在一个很好的thoughtbot talk 中进行了讨论。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-02
        • 1970-01-01
        • 1970-01-01
        • 2012-10-14
        • 2015-09-29
        • 2020-09-11
        • 2022-01-16
        • 1970-01-01
        相关资源
        最近更新 更多