Vim:gg = G左对齐,不自动缩进 [英] Vim: gg=G aligns left, does not auto-indent

查看:124
本文介绍了Vim:gg = G左对齐,不自动缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试用 gg = G 修复HTML文件的缩进时,每一行都会失去缩进并变成左对齐。是否有人知道这里会发生什么?

test.html



 < HTML> 
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8>
< title>缩进测试< / title>
< / head>
< body>
< div id =test>
< div id =test2>
< / div>
< / div>
< / body>
< / html>



运行gg = G后的test.html:



 < HTML> 
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8>
< title>缩进测试< / title>
< / head>
< body>
< div id =test>
< div id =test2>
< / div>
< / div>
< / body>
< / html>



.vimrc



 .vimrc 
Thomas

此文件包含来自各种来源的提示和想法。因为这是个人使用,所以我很懒,大约
分发学分。

谢谢大家。


BASICS
--------------------------
搜索不区分大小写,使用/ searchstring / I暂时禁用。
set ignorecase

需要这些插件才能工作。不知道它做了什么。
filetype插件

自动缩进功能
set ai

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


默认打开行号
设置号码

关闭恼人的错误响铃
set noerrorbells
set visualbell
set t_vb =

以可视方式显示标签和尾随空白http://docs.google.com/View?docid=dfkkkxv5_65d5p3nk
if(& termencoding ==utf-8)||具有(gui_running)
如果v:version> = 700
set list listchars = tab:»\,trail:·,extends:...,nbsp:‗
else
set list listchars = tab:»\,trail:·,extends:...
endif
else
如果v:version> = 700
set list listchars = tab :> \,trail:。,extends:>,nbsp:_
else
set list listchars = tab:> \,trail:。,extends:> ((has('syntax')&&(& t_Co> 2))|| has('gui_running'))$
endif
endif

b $ b语法
endif


BASIC RECONFIGURATION
-------------------- -----

将jj重映射到< esc>
inoremap jj< Esc>
nnoremap JJJJ< Nop>

将选项卡设置为2个字符
set shiftwidth = 2
set softtabstop = 2

将所有临时文件和备份文件保存在〜/ .vim
设置备份
set backupdir =〜/ .vim / backup
set directory =〜/ .vim / tmp

启用漂亮的大viminfo文件
set viminfo ='1000,f1,:1000 ,/ 1000
set history = 500

FUNCTION KEYS
----------------------- -
F7 - 缩进整个文件
map< F7> mzgg = G'z< CR>

F3 - 切换高亮搜索
set hlsearch!
nnoremap< F3> :set hlsearch!< CR>


解决方案

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

  filetype插件上更改此行

.. to this:

  filetype plugin indent on 

...然后重新启动Vim并重试。



有关更多详细信息,请参阅:help filetype-in​​dent-on

When I try to fix the indentation of an HTML file with gg=G, each line loses its indentation and becomes left-justified. Does anybody know what could be going on here?

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>

test.html after running gg=G:

<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>

解决方案

You need to enable loading of indentation files for specific filetypes. Change this line in your .vimrc...

filetype plugin on

..to this:

filetype plugin indent on

...then restart Vim and try again.

See :help filetype-indent-on for more details.

这篇关于Vim:gg = G左对齐,不自动缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆