Vim: gg=G 左对齐,不自动缩进

12

当我尝试使用gg=G修复HTML文件的缩进时,每行都失去了缩进并变成了左对齐。有人知道这是怎么回事吗?

test.html

<html>
   <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Indent test</title>
   </head>
   <body>
    <div id="test">
<div id="test2">
</div>          
    </div>
   </body>
</html>

运行 gg=G 后的 test.html:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Indent test</title>
</head>
<body>
<div id="test">
<div id="test2">
</div>          
</div>
</body>
</html>

.vimrc

".vimrc
" Thomas
"
" This file contains tips and ideas from a wide variety of sources. Since this is for personal use, I'm lazy about
" distributing credit.
"
" Thank you, everybody.
" 

" BASICS
" --------------------------
" Searches are case-insensitive. Use /searchstring/I to disable temporarily.
set ignorecase

" Need this for some plugins to work. Not sure what it does.
filetype plugin on

" Auto-indent facility
set ai

" AESTHEICS
" --------------------------
let g:zenburn_high_Contrast = 1
let g:zenburn_alternate_Visual = 1
colorscheme zenburn 
set lines=53
set columns=130


" Turn on line numbers by default
set number

" Turn off annoying error bells
set noerrorbells
set visualbell
set t_vb=

" Show tabs and trailing whitespace visually http://docs.google.com/View?docid=dfkkkxv5_65d5p3nk 
if (&termencoding == "utf-8") || has("gui_running")
if v:version >= 700
set list listchars=tab:»\ ,trail:·,extends:…,nbsp:‗
else
set list listchars=tab:»\ ,trail:·,extends:…
endif
else
if v:version >= 700
set list listchars=tab:>\ ,trail:.,extends:>,nbsp:_
else
set list listchars=tab:>\ ,trail:.,extends:>
endif
endif

if ((has('syntax') && (&t_Co > 2)) || has('gui_running'))
     syntax on
endif


" BASIC RECONFIGURATION
" -------------------------

" Remap jj to <esc>
inoremap jj <Esc>
nnoremap JJJJ <Nop>

" Set tabs to 2 characters
set shiftwidth=2
set softtabstop=2

" Keep all temporary and backupfiles in ~/.vim 
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp

" Enable nice big viminfo file
set viminfo='1000,f1,:1000,/1000
set history=500

" FUNCTION KEYS
" -------------------------
" F7 - Indent entire file
map <F7> mzgg=G'z<CR>

" F3 - Toggle highlight search 
set hlsearch!
nnoremap <F3> :set hlsearch!<CR>
2个回答

15

您需要启用特定文件类型的缩进文件加载。 在您的.vimrc中更改此行...

filetype plugin on

...变成了这样:

filetype plugin indent on

然后重新启动Vim并再次尝试。

有关详细信息,请参见:help filetype-indent-on


2
你可以重新加载文件 - 无需重启 vim - Draemon

2
也许他没有意识到这是HTML。您能看到语法高亮吗?可以展示一下您的文件和文件名吗?
更新: 请更改以下内容: filetype plugin on -> filetype plugin indent on
希望这样解决了。 问候。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接