如何在 vim 中进行语法检查?
这个问题已经以这样或那样的形式被问了十几次,令我震惊的是没有一个人真正解决如何配置 syntastic 或 jslint 这样它实际上做了它应该做的事情(它的自述文件完全没用)
任何人都可以提供一些分步说明,或此类说明的链接。我尝试安装 jslint 和 Spidermonkey,但没有成功。
我设法使语法检查正常工作(感谢 romainl)。我一路上学到的一些东西可能会帮助任何遇到类似问题的人
- 要构建 Javascript Lint 寻找README 文件嵌套在
jsl-xxx/src/README.html
中 - 构建指令是
gmake -f Makefile.ref
但gmake
是 与make
相同,因此发出命令
sudo ln -s /usr/bin/make /usr/bin/gmake
- jsl 现在可以在
jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl
。要使其普遍可访问,请执行以下操作:ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /home/ForestGump/bin/jsl
。更多信息此处 - 检查 jsl 是否确实有效找到一个测试文件( 此处),然后发出命令
jsl -process test.js
。它应该列出所有错误。 - 要自定义命令行,请将其添加到 vimrc 文件
set statusline=%{SyntasticStatuslineFlag()}
This question has been asked, in one form or another, a dozen times here, and it blows my mind how not a single one actually addresses how to configure syntastic or jslint such that it actually does what it is supposed to do (its README file is completely useless)
Can anyone provide some step by step instructions, or a link to such instructions. I tried to install jslint and spidermonkey, and I got nowhere.
I managed to get the syntax check to work (thanks to romainl). A few things I learned along the way that may help anyone with a similar problem
- To build Javascript Lint look for the README file nested in
jsl-x.x.x/src/README.html
- The build instructions are
gmake -f Makefile.ref
butgmake
is the same thing asmake
so issue the commandsudo ln -s /usr/bin/make /usr/bin/gmake
- jsl will now be found in
jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl
. To make it generally accessible do something like:ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /home/ForestGump/bin/jsl
. More information here - To check that jsl actually works find a test file ( here) then issue the command
jsl -process test.js
. It should list all the errors. - To customize your command line, add this to your vimrc file
set statusline=%{SyntasticStatuslineFlag()}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你做了什么?什么有效,什么无效?您收到错误消息吗?
这就是我所做的:
jsl
源代码。jsl
并将其移至我的$PATH
中的某个位置。:helptags /path/to/syntastic/doc
因为由于某种原因 Pathogen 的自动帮助标签生成对我不起作用。:help syntastic
。步骤 1 到 5 花费的时间不会超过 3 或 4 分钟,甚至可能更少。
无论您尝试什么新工具,第 6 步都是强制性的。 RTFM。
除了我的 .vimrc 中的这三行之外,我不需要配置任何内容(我相信第三行是多余的):
并使用以下命令自定义我的状态行:
编辑
这是我的状态行:
不要逐字复制它,否则你会由于最后的函数调用而出现一些错误。 Syntastic 的帮助中有一段关于此内容的内容。
结束编辑
毕竟,如果您算上阅读文档,需要 10 或 12 分钟,每次我保存带有语法错误的 .js 文件时,我都会弹出一个非常有用的位置列表和标志。
What did you do? What works and what doesn't? Do you get error messages?
Here is what I did:
jsl
sources from the JavaScript Lint site.jsl
and moved it somewhere in my$PATH
.:helptags /path/to/syntastic/doc
because for some reason Pathogen's automatic help tags generation doesn't work for me.:help syntastic
.Steps 1 to 5 didn't take more than 3 or 4 minutes, maybe less.
Step 6 is obligatory, whatever new tool you try. RTFM.
I didn't have to configure anything beside these 3 lines in my .vimrc (and I believe the third is redundant):
and customizing my statusline a bit with:
EDIT
Here is my statusline:
Don't copy it verbatim or you'll get some errors due to the function call at the end. There is a paragraph about that in syntastic's help.
END EDIT
After all that, 10 or 12 minutes if you count reading the documentation, I have a very helpful location list and signs poping up each time I save a .js file with syntax errors.
根据其 README 设置 vundle。
将其放入您的 .vimrc:
然后在 vim 中输入此命令:
就是这样。
编辑:自从我最初写这篇文章以来,Vundle 已经改变了它的语法。如今,您使用
然后输入
Setup vundle according to its README.
Put this into your .vimrc:
Then enter this command in vim:
That's it.
EDIT: Vundle has changed its syntax since I originally wrote this. Nowadays, you use
and then enter