vim缩进:文件中有多种语言
假设我有以下文件:vim缩进:文件中有多种语言,vim,Vim,假设我有以下文件:temp.html正确缩进,它将如下所示: <html> <head> </head> <body> <script type="text/javascript> function blahblahblah(...) { doSomething(); } function so
temp.html
正确缩进,它将如下所示:
<html>
<head>
</head>
<body>
<script type="text/javascript>
function blahblahblah(...) {
doSomething();
}
function something else() {
etc...;
}
</script>
</body>
</html>
<html>
<head>
</head>
<body>
<script type="text/javascript>
function blahblahblah(...) {
doSomething();
}
function something else() {
etc...;
}
</script>
</body>
</html>
函数blahblahblah(…){
doSomething();
}
函数{
等
}
如中所示,我的javascript缩进被搞砸了。我在my.vimrc中有
文件类型插件缩进,它似乎适合我的HTML。但是,我的代码的javascript部分没有正确缩进。如何使用vim正确缩进包含多种代码语言的文件?除非使用更适合该任务的(通常特定于语言的)外部程序,否则缩进混合文件类型在vim中永远不会真正起作用
我推荐哪种格式可以在HTML中格式化JavaScript就好了
下面是我用来格式化纯JS的命令(将其放入~/.vim/after/ftplugin/javascript.vim
):
这些命令的工作方式相同:
:Format " formats the whole buffer
:5,23Format " formats lines 5 to 23
:'<,'>Format " formats the visually selected lines
:Format“格式化整个缓冲区
:5,23格式“设置第5行至第23行的格式
:'
command! -buffer -range=% Format let b:winview = winsaveview() |
\ execute <line1> . "," . <line2> . "!html-beautify -f - -I -s " . &shiftwidth |
\ call winrestview(b:winview)
:Format " formats the whole buffer
:5,23Format " formats lines 5 to 23
:'<,'>Format " formats the visually selected lines