假设set cindent
中有.vimrc
def func()
后跟Enter
,然后输入end
,它缩进(不与def
对齐)
如何重新加入end
关键字(将其与def
对齐)。
即使使用endwise.vim plugin
也无法解决问题
https://github.com/tpope/vim-endwise.git
它会自动添加 end
关键字,但会再次添加indented
答案 0 :(得分:22)
尝试使用smartindent
代替cindent
(遵循类似C的缩进行为),并启用特定于文件类型的缩进。
您可能还需要关闭vi兼容性。
尝试将此添加到您.vimrc:
" Turn off vi compatibility
set nocompatible
set smartindent
set autoindent
" load indent file for the current filetype
filetype indent on
答案 1 :(得分:2)
vimfiles包括ruby代码智能缩进和许多其他有用的东西
ruby代码自动格式化为
class Foo
def bar
if xxx
blah
else
blahblah
end
barfoo
barfoo
end
end
答案 2 :(得分:0)
这对我有用。
" Ruby indentation from http://ubuntuforums.org/showthread.php?t=290462
if has ("autocmd")
filetype indent on
endif
答案 3 :(得分:0)
在我的情况下,这是解决我的缩进问题的原因(例如,在随机位置跳转):
set smartindent
set noautoindent
filetype indent off