简体   繁体   English

如何在vim中跳转到Javascript函数定义?

[英]How to jump to Javascript function definition in vim?

I'm using vim with the tagbar, jsctags and taglist-plus plugins. 我正在使用带有tagbar,jsctags和taglist-plus插件的vim。 They all seem to work correctly, but I cannot jump to a function/variable declaration. 它们似乎都正常工作,但我无法跳转到函数/变量声明。 I tried ctrl+] but it doesn't work. 我试过ctrl +]但它不起作用。 Is it possible to setup vim so that you can jump to a function or variable declaration? 是否可以设置vim以便您可以跳转到函数或变量声明?

Without needing jsctags, I have the following in my ~/.ctags for handling JavaScript correctly: 不需要jsctags,我在〜/ .ctags中有以下内容正确处理JavaScript:

--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*new[ \t]+Object\(/\1/o,object/                                                                                             
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/o,object/
--regex-JavaScript=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/f,function/
--regex-JavaScript=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\([^\]\)]*\)/\1/f,function/
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*new[ \t]+Array\(/\1/a,array/
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/a,array/
--regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*[^""]'[^'']*/\1/s,string/
--regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*[^'']"[^""]*/\1/s,string/

Using the above, a simple ctags -R generates the appropriate tagfile to match JavaScript function (and variable and object) definitions. 使用上面的内容,一个简单的ctags -R生成适当的标记文件以匹配JavaScript函数(以及变量和对象)定义。

TagBar and TagList don't generate the actual tags file used by Vim to jump to definitions. TagBar和TagList不生成Vim用于跳转到定义的实际tags文件。

If you want this ability to jump you have to generate this file manually from the terminal: 如果你想要这种能力跳跃,你必须从终端手动生成这个文件:

$ ctags -R .

if you use ctags or: 如果你使用ctags或:

$ jsctags .

if you use jsctags or from Vim itself. 如果您使用jsctags或来自Vim本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM