在 Vim 中获取 jsDoc intellisense 的最佳方式是什么
我最近开始使用 vim,并且完全迷恋它。
我还没有找到一种很好的方法来使用 jsdoc 注释和 ctags 来获得智能感知或跳转到函数的能力。
你如何做到这一点?
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 ability to jump to a function.
How do you do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不得不说
coc-vim
与一些github 主页面自述文件上建议的键盘映射给了我迄今为止最好的体验,特别是当与 TypeScript 作为语言服务器一起使用时,您可以使用coc-tsserver
coc-vim
扩展。一些示例:
K
将在屏幕顶部显示函数定义/文档的弹出窗口。您还可以获得类似于 VSCode 中的自动完成功能。只需很少的设置,您还可以在屏幕底部的回显区域中获取函数签名。符号上的
gd
将直接带我到该符号的定义。这在 React 中也适用,并将带我到定义该组件的文件。更多工具:
我尚未测试
vim-jsdoc
但从 github 页面的浏览来看,它看起来可以很方便地根据函数签名生成 JSDoc 注释。作为替代方案,
coc-snippets
有一些方便的JSDoc 看起来可能会做类似vim-jsdoc
/jsdoc.vim
。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 thecoc-tsserver
extension ofcoc-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 tovim-jsdoc
/jsdoc.vim
.“类似智能感知”的自动完成功能是通过 autocomplpop 之类的插件获得的或 neocomplcache。如果没有这些插件或标签文件,并且假设您正在编写 JavaScript,则在
myObj.
中的点后输入
将为您提供一个列表本机和自定义属性/方法。我不知道有任何使用 JSDoc 的全方位完成脚本。
"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 inmyObj.
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 不会帮助您进行智能感知,但它会帮助您跳转到函数或类定义:
在 java 项目的顶层执行此操作,然后:
进入 vim 后,按 ctrl+] 跳转到光标下的函数或类名称的定义并按 ctrl+T 跳回。
对于智能感知,请查看 vim 的 ensime - 它也可以在 vim 和 emacs 中完成 scala 和 java 的补全: https:// github.com/MarcWeber/ensime。但设置这一切并不容易,所以要注意:)
另外查看 vim jde 插件,它更容易设置: http://www.vim.org/scripts/script.php?script_id=1213
ctags will not help you with intellisense but it will help you jumping to function or class definitions:
Do that in the top level of your java project, then:
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
Tern 的功能给我留下了深刻的印象。
在分析了我们项目中的代码之后,它可以告诉我哪些全局变量是可见的、它们内部可用的函数以及它们的(某些)参数的类型!
使用 Tern-for-Vim 插件,您可以看到有关自动完成的信息(在分割窗口中包含 jsdocs) ),或者在命令行中显示信息。
不过,这确实需要一些设置。 (
npm install
在插件文件夹内,并创建一个配置文件来告诉 Tern 要查看哪些文件。)您可以将文档绑定到 Javascript 和 Coffeescript 文件的
K
键像这样: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: