这里是 Emacs 用户,正在试用 Vim。 :)
我非常喜欢快速击键和整体理念,但我在使用稍微高级的东西时遇到了一些麻烦。我的提示之一是缩进(使用 =
命令)。
请参阅此 JS 片段。这就是 Emacs 的 js2-mode 缩进的方式。我喜欢这个:
var MyClass = declare([], {
constructor: function(params) {
if(!params) {
params = {};
}
现在这就是 Vim 的用途。该死的 hell :
var MyClass = declare([], {
constructor: function(params) {
if(!params) {
params = {};
}
这个构造之上的所有代码都得到了适当的缩进,但从那里开始就很糟糕了。我的代码中到处都有这种结构。我检查了 :filetype
并打开了这些开关。我尝试过使用和不使用插件。没搞对。 Vim 是 gVim 7.4,几天前下载的。我见过this question并且显示的代码片段已正确缩进,开箱即用。
有人知道我可以在这里尝试什么吗? 感谢您的任何建议!
最佳答案
在你的.vimrc
中:
set nocompatible " vi is decades old
set expandtab " use soft tabs set shiftwidth=2 # 2 spaces tabs for JS (?) set softtabstop=2
filetype on
filetype plugin on
filetype plugin indent on " auto indent for supported languages (JS included)
要重新格式化所有文件,请输入 gg=G
gg -> go to top of file
= -> indent
G -> until the end of the file
关于javascript - 我怎样才能让 Vim 得到正确的 JS 缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25266743/