Reputation: 79
Here is my ~/.vimrc file. My indentation works for vim, but does not work for MacVim. Every time I open MacVim and try scripting in python I have to click Edit --> File Settings --> Shiftwidth --> 2
What corrections do I need to make to my ~/.vimrc file? I even considered making an exact replica of my ~/.vimrc file and called it ~/.mvimrc.
1 set nocompatible
2
3 execute pathogen#infect()
4 syntax on
5 filetype plugin indent on
6 set noai ai
7 set nosi si
8 set nosta sta
9 set shiftwidth=2
10 set softtabstop=2
11 set ts=2
12 set expandtab
13 set number
14
15 set statusline+=%#warningmsg#
16 set statusline+=%{SyntasticStatuslineFlag()}
17 set statusline+=%*
18
19 let g:syntastic_always_populate_loc_list = 1
20 let g:syntastic_auto_loc_list = 1
21 let g:syntastic_check_on_open = 1
22 let g:syntastic_check_on_wq = 0
23
"~/.vimrc" [readonly] 31L, 589C
Upvotes: 1
Views: 1601
Reputation: 196781
In the past, the Python ftplugin only took care of "generic" stuff but a semi-recent update added indentation settings in an effort to enforce PEP8 compliance:
" As suggested by PEP8.
setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
A clean way to override those settings would be to add the lines below to ~/.vim/after/ftplugin/python.vim
:
setlocal shiftwidth=2
setlocal softtabstop=2
A few comments about your vimrc
:
set nocompatible generally useless, remove this line
set noai ai needlessly complex and ambiguous, use set autoindent
set nosi si smartindent is useless, remove this line
set nosta sta needlessly complex and ambiguous, use set smarttab
set ts=2 useless, 'tabstop' should be left at its default value
Upvotes: 2
Reputation: 391
Do your plugins and other settings load in macvim, or is it having issues detecting your .vimrc completely? If it's completely not finding it, you might want to check this question and see if you can fix it. If it's only happening to python, is it possible you have a plugin that is changing shiftwidth? If so you may want to look into using after to do it. If your vimrc is loading, you might want to try doing this to set the shiftwidth to 2 for python files only...
You can use Autocommand to detect that you are editing a .py filetype and change shiftwidth.
autocmd Filetype py setl shiftwidth=2
Above that line, you may need to put this:
filetype on
Put both these in your vimrc to make it work.
Pretty self explanatory, but just to spell out what it does, when it detects a .py file, it sets the shift width to 2. Setl is shorthand for setlocal (to the buffer).
Upvotes: 0