JavaScript 语法 & Vim 中的缩进
我知道以前有人问过这个问题,但我在让 JavaScript 缩进在 Vim 中正常工作时遇到了困难。
我尝试安装这个插件:
http://www.vim.org/scripts/script .php?script_id=3081
我得到了这个行为:
if (x == 1) {
alert("nice");
}
这是我的 vimrc:
syntax on
set background=light
colorscheme solarized
set tabstop=4
filetype plugin indent on
let g:solarized_termcolors=16
我也用这个插件尝试过:
http://www.vim.org/scripts/script.php?script_id=1840
但这给了我这个:
if (x == 1) {
alert("nice");
}
即两个选项卡,我只希望它缩进一个选项卡。
有人知道在这里做什么吗?
I know this has been asked before, but I'm having trouble getting JavaScript indentation to work properly in Vim.
I tried installing this plugin:
http://www.vim.org/scripts/script.php?script_id=3081
And I get this behaviour:
if (x == 1) {
alert("nice");
}
This is my vimrc:
syntax on
set background=light
colorscheme solarized
set tabstop=4
filetype plugin indent on
let g:solarized_termcolors=16
I also tried it with this plugin:
http://www.vim.org/scripts/script.php?script_id=1840
But that gives me this:
if (x == 1) {
alert("nice");
}
i.e., two tabs, where I only want it to indent by a single tab.
Anyone have any ideas what to do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Vim wiki 解释了如何设置特定于文件类型的缩进,而且非常简单: http://vim .wikia.com/wiki/Indenting_source_code#Different_settings_for_ Different_file_types
最简单的方法是
.vimrc
文件中的autocmd FileType
指令。您可以分别为每种文件类型指定缩进:或为所有文件类型设置默认缩进,并为特定文件类型覆盖它:
Vim wiki explains how to setup filetype-specific indentation, and it's pretty straight-forward: http://vim.wikia.com/wiki/Indenting_source_code#Different_settings_for_different_file_types
The simplest way is to put
autocmd FileType
instructions in your.vimrc
file. You can specify indentation for each file type separately:or set default indentation for all file types, and override it for the specific ones:
我从谷歌来到这里,对上面建议的赵一的缩进文件不满意。仍然没有捕获我的一些嵌套函数。
我在 Twitter 上四处询问,有人建议 https://github.com/pangloss/vim-javascript - 我对此感到高兴得多。
哈特哈,
I came here from google and was unsatisfied with Yi Zhao's indent file as suggested above. Still wasn't catching some nested functions of mine.
I asked around on twitter and was suggested https://github.com/pangloss/vim-javascript - with which I am far happier.
HTH,
你有没有在你的.vimrc编辑中尝试过这个,
我用于VIM的JavaScript“插件”是 javascript.vim 替换默认的 VIM javascript 语法文件。
无论您使用什么插件,VIM 中的缩进通常都非常糟糕,并且是 VIM 用户(尤其是 JavaScript 用户)的常见抱怨。没有完美的解决方案,考虑到 VIM 强大的扩展性,这很奇怪。
Have you tried this in your .vimrc
edit also the JavaScript "plugin" I use for VIM is javascript.vim which replaces the default VIM javascript syntax file.
No matter what plugins you use, indenting in VIM is usually pretty bad, and is a common complaint with VIM users, especially with JavaScript. There is no perfect solution, which is strange considering the powerful extensibility of VIM.