Vim 没有自动缩进我正在处理的 C 源文件,尽管它声称在我键入时启用了 autoindent 和 cindent 选项
:放
命令。
当我输入一些代码时什么也没有发生。例如写作
int main()
{
return 0;
}
“返回0;”语句保留在左侧。
但是,如果我输入“=G”命令,我的文件就会缩进。
这是我的配置:
vimrc 分为/etc/vim/vimrc 和 ~/.vimrc。拼接后的内容如下:
runtime! debian.vim
if has("syntax")
syntax on
endif
set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
if has("autocmd")
filetype plugin indent on
endif
set showcmd
set showmatch
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
""""""" now this is ~/.vimrc """""
set runtimepath+=,/usr/share/vim-scripts
set autoindent
set noexpandtab
" create ~<file> when saving modifications to <file>
set backup
" preserve source's format when pasting
set paste
" disable mouse usage
set mouse=
" colors
set t_Co=256
colorscheme mustang
set hlsearch
set number
set cursorline
if has("statusline")
hi User1 ctermbg=red cterm=bold,reverse
hi User2 ctermbg=darkblue cterm=bold,reverse
hi User3 ctermbg=darkred cterm=bold,reverse
hi User4 ctermbg=brown cterm=bold,reverse
set laststatus=2
set statusline=%h%f\ %y\ %1*%r%*%1*%m%*%=[col:%2*%c%*]\ [line:%3*%.6l%*/%4*%.6L%*\ -\ %p%%]
endif
set spellsuggest=5
match Error /\s\+$/
你有什么主意吗 ?
非常感谢您的帮助。
皮埃尔
最佳答案
在将 :help paste
添加到 set paste
之前,您应该阅读 ~/.vimrc
:
When the 'paste' option is switched on (also when it was already on):
... skipped ...
- 'autoindent' is reset
... skipped ...
These options keep their value, but their effect is disabled:
... skipped ...
- 'cindent'
'paste'
是非常有毒的,永远不应该添加到一个人的 ~/.vimrc
中。请参阅 :help pastetoggle
和/或改用 p
。关于vim:smartindent(或cindent)已激活但不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17104675/