I am recovering from a surgery, thusly, I am transitioning to VIM. As I starting point, I\'ve opted to use the vim-sensible plugin as the foundation of my configuration. Addit
In my vimrc I have the following:
set autoindent
set expandtabs
set shiftwidth=4
set tabstop=4
Actually I just have
set ai et sw=4 ts=4
You can change the specific settings using FileType
or BufEnter
:
autocmd BufEnter *.py ai et sw=4 ts=4
Vim provides the following buffer local options for managing indention: 'softtabstop'
, 'shiftwidth'
, 'tabstop'
, and 'expandtab'
. The idea is to set these options for a specific filetype, e.g. ruby
either by using an autocommand
or using the after ftplugin directory (my preference).
Add the following to your ~/.vim/after/ftplugin/ruby.vim
file:
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal tabstop=2
Add the following to your ~/.vimrc
file:
augroup MyIndentSettings
autocmd!
autocmd FileType ruby setlocal softtabstop=2 shiftwidth=2 tabstop=2
augroup END
As you are just starting to vim it is best to learn how to query these options so you can track down future bugs. Querying an option is as simple as :verbose set {option}?
, e.g. :verbose set expandtab?
.
You may also be interested in Tim Pope's vim-sleuth which heuristically sets indent settings.
For more help see:
:h :set
:h 'softtabstop'
:h 'shiftwidth'
:h 'tabstop'
:h 'expandtab'
:h after-directory