假设.vimrc
中有set cindent
def func()
后面跟着Enter
,然后输入end
,它是缩进的(不与def
对齐)
如何重新缩进end
关键字(使其与def
对齐)。
即使使用endwise.vim plugin
也不能解决问题
https://github.com/tpope/vim-endwise.git
它自动添加了 end
关键字但是indented
尝试使用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
vimfiles包含ruby代码智能缩进和许多其他有用的东西
ruby代码会自动格式化为
class Foo
def bar
if xxx
blah
else
blahblah
end
barfoo
barfoo
end
end
在我的例子中,这就是解决缩进问题的方法(例如在随机位置跳跃):
set smartindent
set noautoindent
filetype indent off
这对我很有效。
" Ruby indentation from http://ubuntuforums.org/showthread.php?t=290462
if has ("autocmd")
filetype indent on
endif