suppose I have set cindent
in .vimrc
def func()
followed by Enter
, and then type end
, it is indented(not aligned to the def
)
How to reindent the end
keyword(align it to the def
).
Even using endwise.vim plugin
doesn't fix the problem
https://github.com/tpope/vim-endwise.git
It adds automatically the end
keyword but again indented
To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing. If you set the auto-indent feature in Vim in command mode, it does not persist upon closing the editor.
Fix indentation in the whole fileStart in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.
How to Turn Off Vim Auto Indent. You can also temporarily turn off automatic indenting by typing :set paste in command mode. (:unset paste to turn it back on again.) This is useful — as you might guess from the command name — if you're pasting in chunks of text or code to avoid getting annoying extraneous indents.
It's possible to reformat an entire file, or a section of a file, using Vim's built-in = filter. Vim veterans often find this operator to be one of the most useful in their repertoire, but so common that it becomes second-nature and is rarely mentioned. In normal mode, typing gg=G will reindent the entire file.
Try using smartindent
instead of cindent
(which follows C-like indent behaviour), and turn on the filetype specific indent.
You'll also probably need to turn off vi compatibility.
Try adding this to you .vimrc:
" Turn off vi compatibility
set nocompatible
set smartindent
set autoindent
" load indent file for the current filetype
filetype indent on
vimfiles includes ruby code smart indention and a lot of other useful things
ruby code is automatically formatted like
class Foo
def bar
if xxx
blah
else
blahblah
end
barfoo
barfoo
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With