在这种情况下,如何让 Vim 正确地进行语法高亮显示(例如与 Knockout templates 一起使用):
<script type="text/html" id="my-template">
<!-- This should be rendered as HTML -->
<div>Some template</div>
</script>
<script>
//This should be rendered as Javascript
var x = function() { return 3; }
</script>
给出的解决方案here涉及编辑Vim的内部语法文件,这似乎是错误的,它专门寻找“text/javascript
”即no longer needed in <script>
tags .
我假设解决方案是我可以保留在我的 .vim
中的某种语法插件目录,但对 Vim 的内部语法不够熟悉,无法理解。
(注意 this question and answer 不适用,因为我没有使用 Ruby on Rails。)
最佳答案
也许这会对您有所帮助:https://coderwall.com/p/vgk5-q/make-vim-play-nice-with-html-templates-inside-script-tags .
万一上面的链接有一天坏了 - 将以下代码放入 ~/.vim/after/syntax/html.vim
:
unlet b:current_syntax
syn include @HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/template[^>]*>+
\ end=+</script>+me=s-1 keepend
\ contains=@HTML,htmlScriptTag,@htmlPreproc
有人应该为此写一个插件! ;)
关于javascript - 让 Vim 正确高亮脚本类型 ="text/html",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24317073/