I like to use tabs for indentation (hey, don't bully me!). But 33% of other programmers prefer spaces.
The norm with Python is to use spaces for indetation. Even so, I configured Vim to use tabs with Python since I recently worked on Python code that was indented with tabs. But right now I'm working on some other Python project which has spaces for indentation...
So now I want to make Vim figure out which kind of indentation the file uses and indent accordingly. So my question is how can I accomplish that?
I discovered the copyindent option, which seems to solve the problem. But I am unsure whether this is the correct way to solve the problem. Does it have any pitfall? Is there a better way to do this?
For the sake of completeness, these are the contents of my .vim/after/ftplugin/python.vim file, which is the one ensuring tabs are used for Python right now. I also have filetype plugin indent on in my .vimrc.
setlocal tabstop=4
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal textwidth=80
setlocal smarttab
setlocal noexpandtab
if search('^\t', 'wn') | setlocal noexpandtab | else | setlocal expandtab | endif, where you could replace those|s by newlines in your plugin. – garyjohn Oct 23 '15 at 23:42autocmd FileType python setlocal ts=4 sts=4 sw=4 noexpandtab, asftplugin/python.vimoverwrites this. I sent a message to the mailinglist about this, but it didn't get changed, so well :-/ – Martin Tournoij Dec 17 '15 at 13:46