如何在Vim中自动添加Ruby源代码

use*_*693 12 ruby vim auto-indent

假设我有set cindent.vimrc
def func()后面Enter,然后键入end,它缩进(不对齐def)

如何缩进的end关键字(将其调整到def).

即使使用endwise.vim plugin不解决问题
https://github.com/tpope/vim-endwise.git
它增加了自动end关键字,但再次indented

m0t*_*ive 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
Run Code Online (Sandbox Code Playgroud)


zed*_*xff 1

vimfiles包括 ruby​​ 代码智能缩进和许多其他有用的东西

ruby 代码自动格式化为

class Foo
  def bar
    if xxx
      blah
    else
      blahblah
    end
    barfoo
    barfoo
  end
end
Run Code Online (Sandbox Code Playgroud)