Vim 如何在:%left和gg=G之后获得相同的smartindent结果

Vim 如何在:%left和gg=G之后获得相同的smartindent结果,vim,cygwin,indentation,vi,Vim,Cygwin,Indentation,Vi,我对vim的使用还相当陌生,所以如果这是一个非常简单的问题,请耐心等待。问题是,我在我的.vimrc中设置了smartindent(基本上只有这一个w.r.t.缩进),它按照我的预期工作,例如,在将下面的代码写入js文件后,它缩进了2个制表符(或8个空格)的间距(我认为是默认选项): 如果我用:%left删除缩进,然后用gg=G自动缩进整个文件,我得到: 1 sjsjs function(sjdhd, jdjd,{ 2 aaaa, 3

我对vim的使用还相当陌生,所以如果这是一个非常简单的问题,请耐心等待。问题是,我在我的.vimrc中设置了smartindent(基本上只有这一个w.r.t.缩进),它按照我的预期工作,例如,在将下面的代码写入js文件后,它缩进了2个制表符(或8个空格)的间距(我认为是默认选项):

如果我用:%left删除缩进,然后用gg=G自动缩进整个文件,我得到:

 1 sjsjs function(sjdhd, jdjd,{
 2                 aaaa,
 3                 bbbb,
 4                 cccc,
 5                 dddd
 6                 });
如果我使用“autoindent”和“filetype plugin indent on”,我会得到一个奇怪的行为,它会缩进dddd行,如果我添加eeee,它会产生一个双缩进(smartindent在花括号内保持相同的缩进):

在:%left和gg=G之后,如何获得smartindent方式?此外,我想整理我的代码(不仅在JS,但C++,shell,HTML),所以他们看起来很缩进(例如,没有太多的缩进,我认为CIMTUNT产生过多的缩进)。你能推荐一个好的缩进设置吗?我知道最后一个问题可能有成千上万的答案/方法,但我还是想提出一些建议

提前感谢,

附言

$vim--版本
VIM-Vi改进了7.4(2013年8月10日,2014年8月28日01:24:00)
附带补丁:1-417
编者
$grep set.vimrc
兼容模式
“设置退格=缩进、下线、开始
set nobackup“不要保留备份文件,请改用版本
设置备份“保留备份文件(还原到以前的版本)
设置撤消文件“保留撤消文件(关闭后撤消更改)
设置历史记录=50“保留50行命令行历史记录
“设置标尺”始终显示光标位置
设置showcmd“显示不完整的命令
设置incsearch“执行增量搜索
设置鼠标-=a
高亮显示
autocmd文件类型文本集本地文本宽度=78
“设置自动缩进”始终将自动缩进设置为打开
命令DiffOrig vert new | set bt=nofile | r++edit | 0d | diffthis
设置背景=灯光
设定数
智能对齐

智能缩进
是一种过时的选项/机制;应将该行替换为以下两行:

filetype plugin indent on
set autoindent

第一个激活了通常更智能的特定于文件类型的缩进,第二个激活了空缓冲区的基本自动缩进。

阅读后,我发现最好是使用与所用文件格式相关的特定插件。对于javascript,这个插件就完成了这个任务。我刚刚删除了smartindent等人并使用了该插件。

我尝试了两者而不是smartindent,并且不喜欢输出,我将用一个示例更新我的问题
  1 sjsjs function(sjdhd, jdjd,{
  2         aaaa,
  3         bbbb,
  4         cccc,
  5                 dddd
  6 });
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 28 2014 01:24:00)
Included patches: 1-417
Compiled by <cygwin@cygwin.com>


$ grep set .vimrc
set nocompatible
"set backspace=indent,eol,start
  set nobackup          " do not keep a backup file, use versions instead
  set backup            " keep a backup file (restore to previous version)
  set undofile          " keep an undo file (undo changes after closing)
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set incsearch           " do incremental searching
  set mouse-=a
  set hlsearch
  autocmd FileType text setlocal textwidth=78
"  set autoindent               " always set autoindenting on
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
set background=light
set number
set smartindent
filetype plugin indent on
set autoindent