简体   繁体   English

Vim:内联JavaScript语法比单独显示文件更好地突出显示

[英]Vim: inline JavaScript syntax highlighting better than on a separate file

When editing JavaScript inside a script tag the syntax highlighting is much better than when editing myFile.js. 在脚本标签中编辑JavaScript时,语法突出显示比编辑myFile.js时要好得多。

Is there a way to have the same syntax highlighting in a separate file as you have inside a script tag? 有没有办法在单独的文件中与在script标记中具有相同的语法突出显示?

I already tested both the stock javascript.vim syntax file and this alternative one: http://www.vim.org/scripts/script.php?script_id=1491 ! 我已经测试了常规javascript.vim语法文件和此备用文件: http : //www.vim.org/scripts/script.php ? script_id=1491

edit: please check screen shot: 编辑:请检查屏幕截图: 在此处输入图片说明

Left side is inside script tags and :setfiletype html. 左侧是脚本标记和:setfiletype html。 Right side is plain javascript with :setfiletype javascript 右侧是带有:setfiletype javascript的普通javascript

I know it's been a couple of months, but I wonder if you've found a satisfactory answer yet? 我知道已经过去了几个月,但我想知道您是否找到满意的答案?

I found the following via :help syntax within vim: 我在vim中通过:help语法找到了以下内容:

JavaScript and Visual Basic embedded inside HTML documents are highlighted as 'Special' with statements, comments, strings and so on colored as in standard programming languages. 嵌入在HTML文档中的JavaScript和Visual Basic突出显示为“特殊”,带有声明,注释,字符串等,其颜色与标准编程语言中的颜色相同。 Note that only JavaScript and Visual Basic are currently supported, no other scripting language has been added yet. 请注意,当前仅支持JavaScript和Visual Basic,尚未添加其他脚本语言。

This seems to explain why everything that is does not have its own coloring in javascript.vim is colored "Special" when embedded within HTML. 这似乎可以解释为什么当嵌入HTML时,javascript.vim中所有没有颜色的东西都被涂上“特殊”颜色的原因。 This seems to include variable names, function and method names, and so forth. 这似乎包括变量名,函数和方法名,等等。 I like it, too, because it separates variables, etc, from punctuation, etc. Much easier to see that your code is correct. 我也喜欢它,因为它可以将变量等与标点符号等分开。更容易看到您的代码正确。

In my case installing jelera/vim-javascript-syntax did the trick since vim-javascript plugin by itself didn't apply a nice color syntax. 在我的情况下,安装jelera / vim-javascript-syntax可以解决问题 ,因为vim-javascript插件本身并没有应用漂亮的颜色语法。 If your language of choice is Javascript (as in my case) I recommend you to follow this great guide . 如果您选择的语言是Javascript(例如我的情况),建议您遵循本指南 Hope this helps! 希望这可以帮助!

My vim JavaScript highlighting is awesome, this is my setup: 我的vim JavaScript高亮显示很棒,这是我的设置:

syntax on
filetype plugin on
syntax enable
au BufRead,BufNewFile *.js set filetype=javascript
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS

with the following js-related bundles 与以下与js相关的捆绑软件

jslint

and no specific syntax files 没有特定的语法文件

My colorscheme (molokai) takes care of the rest 我的colorscheme(molokai)负责其余的工作

Hope this helps you 希望这对您有帮助

Use vim-javascript . 使用vim-javascript It works pretty well. 效果很好。

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

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