开发者

What's the best way to get jsDoc intellisense in Vim

I have recently converted to using vim and am completely sold on it.

I haven't found a nice way to use jsdoc comments with ctags to get intellisense or the abi开发者_运维知识库lity to jump to a function.

How do you do this?


I'd have to say that coc-vim with some of the suggested keymappings on the main github page readme have given me the best experience by far, especially when used with TypeScript as a language server, which you can do with the coc-tsserver extension of coc-vim.

Some examples:

<SHIFT>K will show a popup of the function definition/documentation at the top of my screen. You also get auto-complete similar to what you would get in VSCode. With little setup you can also get function signatures in the echo area at the bottom of your screen.

gd over a symbol will take me straight to the definition of that symbol. This works in React too and will take me to the file that the component is defined in.

More tools:

I haven't yet tested vim-jsdoc but from a skim of the github page, it looks handy for generating JSDoc comments based on function signatures.

As an alternative, coc-snippets has some a handy one for JSDoc that looks like it may do something similar to vim-jsdoc/jsdoc.vim.


"Intellisense-like" auto-completion is obtained through a plugin like autocomplpop or neocomplcache. Without these plugins or a tags file, and assuming you are writing JavaScript, typing <C-x><C-o> after the point in myObj. will give you a list of native AND custom properties/methods.

I don't know of any omni-completion script that makes use of JSDoc.


ctags will not help you with intellisense but it will help you jumping to function or class definitions:

$ ctags -R *

Do that in the top level of your java project, then:

$ vi -t functionName    # or ClassName

Once inside vim, ctrl+] to jump to definition of function or class name under the cursor and ctrl+T to jump back.

For intellisense, check out ensime for vim - it can do completion for scala and java in vim and emacs too: https://github.com/MarcWeber/ensime. But setting it all up is not tha easy so be warned :)

Also check out vim jde plugin which is easier to setup: http://www.vim.org/scripts/script.php?script_id=1213


I was impressed by the capabilities of Tern.

After analysing the code in our project, it could tell me what globals would be visible, the functions available inside them, and the types of (some of) their arguments!

With the Tern-for-Vim plugin, you can see this information on autocompletion (with jsdocs in a split window), or have information displayed in the command line.

It does take a little setting up though. (npm install inside the plugin folder, and create a config file to tell Tern which files to look at.)

You could bind documentation to the K key for Javascript and Coffeescript files like this:

autocmd BufReadPost *.{js,coffee} nnoremap <buffer> K :TernDoc<CR>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜