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

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

问题描述

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

test.html

<头><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>缩进测试</title><身体><div id="测试"><div id="test2">

运行 gg=G 后的 test.html:

<头><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>缩进测试</title><身体><div id="测试"><div id="test2">

.vimrc

".vimrc托马斯"" 该文件包含来自各种来源的提示和想法.由于这是供个人使用的,我很懒惰分配信用.""谢谢大家.""基本" --------------------------" 搜索不区分大小写.使用/searchstring/I 暂时禁用.设置忽略大小写" 一些插件需要这个才能工作.不确定它的作用.文件类型插件" 自动缩进功能设置爱" 美学" --------------------------让 g:zenburn_high_Contrast = 1让 g:zenburn_alternate_Visual = 1colorcheme zenburn设置行=53设置列=130" 默认开启行号套数" 关闭烦人的错误铃声设置无误设置可视铃设置 t_vb=" 直观地显示制表符和尾随空格 http://docs.google.com/View?docid=dfkkkxv5_65d5p3nkif (&termencoding == "utf-8") ||有(gui_running")如果 v:version >= 700设置列表 listchars=tab:» ,trail:·,extends:...,nbsp:‗别的设置列表 listchars=tab:» ,trail:·,extends:...万一别的如果 v:version >= 700设置列表 listchars=tab:> ,trail:.,extends:>,nbsp:_别的设置列表 listchars=tab:> ,trail:.,extends:>万一万一if (((has('syntax') && (&t_Co > 2)) || has('gui_running'))语法上万一" 基本重新配置" -------------------------" 将 jj 重新映射到 <esc>inoremap jj nnoremap JJJJ " 将制表符设置为 2 个字符设置 shiftwidth=2设置 softtabstop=2" 将所有临时和备份文件保存在 ~/.vim 中设置备份设置备份目录=~/.vim/backup设置目录=~/.vim/tmp" 启用漂亮的大 viminfo 文件设置 viminfo='1000,f1,:1000,/1000设置历史=500" 功能键" -------------------------" F7 - 缩进整个文件地图 <F7>mzgg=G'z CR ;" F3 - 切换高亮搜索设置 hlsearch!nnoremap <F3>:set hlsearch!

解决方案

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

中更改这一行

文件类型插件

...至此:

文件类型插件缩进

...然后重启 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天全站免登陆