Vim ruby ​​identation

I am learning Vim and should do the following: Suppose I typed this:

class MyClass
private
end

After input, gg=GI want to privatestay at the level with the class declaration, for example:

class MyClass
private
end

But it looks wrong (the indent moves privateto the right):

class MyClass
  private
end

How can I add a custom rule to auto-detect private?

+4
source share
2 answers

As already mentioned, vim uses the recommended indent: https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected

However, if you want to change it, you can set a custom indentexpr

autocmd FileType ruby setlocal indentexpr=YourCustomFunction()

​​ . , vim , .

P.S. Rubocop , , , , private, .

+2

, Vim , .vimrc:

let g:ruby_indent_access_modifier_style = 'outdent'

, Ruby Vim, vim-ruby ().

, Vim. , , , vim-ruby , - , ( , - heredoc).

+1

Source: https://habr.com/ru/post/1687889/


All Articles