问题
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. Additionally, I've installed the 'vim-rails' and 'vim-ruby' plugins. These are all loaded via Pathogen.
For whatever reason, the plugins are not adjusting indentation settings in accord with filetype. Tabs seem locked to 9 columns. I am able to set them manually, but obviously this is not ideal.
Here is my .vimrc. As you can see, it is very basic.
execute pathogen#infect()
syntax on
filetype plugin indent on
回答1:
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).
After directory approach
Add the following to your ~/.vim/after/ftplugin/ruby.vim
file:
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal tabstop=2
Autocommand approach
Add the following to your ~/.vimrc
file:
augroup MyIndentSettings
autocmd!
autocmd FileType ruby setlocal softtabstop=2 shiftwidth=2 tabstop=2
augroup END
Learn more
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
回答2:
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
来源:https://stackoverflow.com/questions/27804353/transitioning-to-vim-having-issues-with-indentation