As a solution to the problem described in the question Why does vim not obey my expandtab in python files?, I have added this to my vimrc:
let g:use_tabs = 1
let g:indent_width = 4
let g:tab_width = 4
function! SetIndent()
if g:use_tabs
set noexpandtab
set softtabstop=0
let &shiftwidth = g:indent_width
let &tabstop = g:tab_width
else
set expandtab
let &softtabstop = g:indent_width
let &shiftwidth = g:indent_width
let &tabstop = g:tab_width
endif
endfunction
autocmd VimEnter * call SetIndent()
This works perfectly when running vim in a terminal, but it seems like MacVim doesn't run the call SetIndent()
command at all.
Is this because MacVim ignores VimEnter
or runs it at another time than vim?
How would I fix my vimrc so it also work in MacVim?
Edit: Link to my full vimrc: https://ghostbin.com/paste/3xnw7
The default settings for Python are:
setlocal tabstop=8
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal expandtab
If you want to change, say… 'expandtab'
, you only have to put the line below in ~/.vim/after/ftplugin/python.vim
:
setlocal noexpandtab
Yes, you are expected to do that for every filetype for which you don't like the default settings. It is a lot simpler, quicker, more dependable and more maintainable than using a function.
KISS.