[英]vim: autoindent not working
my autoindent is not working, any diagnostic tests to figure it out?我的自动缩进不起作用,是否有任何诊断测试来解决这个问题?
my ":set" is:我的“:设置”是:
:set --- Options --- cindent laststatus=2 scroll=17
:set --- 选项 --- cindent laststatus=2 scroll=17
tabstop=4 window=36制表位 = 4 窗口 = 36
filetype=cpp number文件类型=cpp 编号
smartindent ttyfastsmartindent ttyfast
helplang=en pastehelplang=en 粘贴
syntax=cpp ttymouse=xterm2语法=cpp ttymouse=xterm2
backspace=indent,eol,start退格=缩进,eol,开始
fileencoding=utf-8文件编码=utf-8
fileencodings=ucs-bom,utf-8,default,latin1 printoptions=paper:letterfileencodings=ucs-bom,utf-8,default,latin1 printoptions=paper:letter
runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/af ter,/var/lib/vim/addons/after,~/.vim/after suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc运行时路径=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/after,/var/lib /vim/addons/after,~/.vim/after 后缀=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb, .ind、.idx、.ilg、.inx、.out、.toc
try:尝试:
:set ai
or:或者:
:set autoindent
find more about auto-indent:查找有关自动缩进的更多信息:
:h ai
Otherwise, it's might be something with file type detection.否则,它可能与文件类型检测有关。
I had a stale function in indentexpr
which persisted after changing the filetype.我在
indentexpr
有一个陈旧的函数,它在更改文件类型后仍然存在。 This eventually fixed it for me:这最终为我修复了它:
:set indentexpr=
In case someone else face the same issue, I had a similar issue that none of the above fixed.万一其他人面临同样的问题,我有一个类似的问题,上述问题都没有解决。 What was wrong for me was the tab interpretations.
对我来说错误的是标签解释。 here is the set up that made it work:
这是使其工作的设置:
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
And to check when indenting if the indentation was correct, I added the following, still in my vimrc file:为了检查缩进时缩进是否正确,我添加了以下内容,仍然在我的 vimrc 文件中:
" helper for indent mistake
set list listchars=tab:»·,trail:·
Which display a "»" instead of the regular "·" if my indent is wrong.如果缩进错误,则显示“»”而不是常规的“·”。 Very handy.
非常便利。 Hope it helps.
希望能帮助到你。
I had the same issue and these settings fixed it.我有同样的问题,这些设置修复了它。
filetype on
filetype plugin on
filetype indent on
您可能应该关闭smartindent
并使用:filetype indent on
和cindent
(似乎也已设置)。
Here's one way to test out whether you have the configuration correct, then persist your configuration so Vim always operates thusly.这是测试您的配置是否正确的一种方法,然后保留您的配置以便 Vim 始终如此运行。
This font
indicates text which should be typed in literally, except <CR>
means press the "Enter" or "Return" key. This font
表示应按字面输入的文本,除了<CR>
表示按“Enter”或“Return”键。
:set ai?<CR>
):set ai?<CR>
):set ai<CR>
):set ai<CR>
):set ai?<CR>
):set ai?<CR>
):mkvimrc<CR>
.:mkvimrc<CR>
。 Hope that helps!希望有帮助! Here are some other notes:
以下是一些其他注意事项:
"The 'autoindent' option is reset when the 'paste' option is set". “当设置 'paste' 选项时,'autoindent' 选项被重置”。 So try to remove 'paste' from your settings ( vim-options ).
因此,请尝试从您的设置( vim-options )中删除“粘贴”。
I had the same problem, and I have tried many commands, all failed.我有同样的问题,我尝试了很多命令,都失败了。
At last, I use the following command, and it works:最后,我使用以下命令,它有效:
autocmd VimEnter * set autoindent
It's not a elegant method, however, it does works.这不是一个优雅的方法,但是,它确实有效。
:set smartindent?
showd: nosmartindent
显示:
nosmartindent
Then activating it with :set smartindent
solved problem for me.然后用
:set smartindent
激活它为我解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.