Vim Omni Completion 在 JS const 和 let 声明上失败

Vim Omni Completion Fails on JS const and let Declarations

Omni Completion 仅查找使用 var 关键字声明的变量的模式。无法找到用 constlet 声明的变量。

const apple
let blueberry
var carrot
// Omni Completion only finds patterns for 'carrot'

~/.vimrc

"Start pathogen plugin manager
execute pathogen#infect()

"Enable syntax, changing font/colors
syntax on

"FILETYPE DETECTION
"Enable file type detection
filetype on
"Enable loading file type plugins
filetype plugin on
"Enable loading indent file
filetype indent on

"TABS
"expand tabs to spaces
set expandtab
"spaces for automatic indents
set shiftwidth=2
"make existing tabs appear like 2 spaces
set softtabstop=2

"MAPS
"map jk to escape
:inoremap jk <Esc>

"map omnicompletion to space
"
"For some reason <C-Space> is interpreted as <C-@>
inoremap <C-@> <C-x><C-o>

"APPEARANCE
"turn on relative line numbers
set number relativenumber

"Omnicompletion (autocompletion)
set omnifunc=syntaxcomplete#Complete

我在找到 Tern 之后推断 Vim 的 Omni Completion 功能缺乏深度 JavaScript 补全功能。来自 Tern 主页:

Tern is a stand-alone code-analysis engine for JavaScript. It is intended to be used with a code editor plugin to enhance the editor's support for intelligent JavaScript editing. Features provided are:

  • Autocompletion on variables and properties
  • Function argument hints
  • Querying the type of an expression
  • Finding the definition of something
  • Automatic refactoring

Tern is open-source (MIT license), written in JavaScript, and capable of running both on node.js and in the browser.

然后我找到了 tern_for_vim GitHub repo, and a tutorial for setting it up

在使用 Pathogen 作为 Vim 插件管理器的情况下,来自 tern_for_vim GitHub 存储库自述文件:

If you use Pathogen or something similar, you can clone this repository to your ~/.vim/bundle (or equivalent) directory. Make sure you have node.js and npm installed (Tern is a JavaScript program), and install the tern server by running npm install in the bundle/tern_for_vim directory.