Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my .vimrc file I have this line..

filetype plugin indent on

and then in ~/.vim/ftplugin/py.vimrc (I've also tried saving it as a .vim file) I've copied and pasted a vimrc file for python standards and have enabled all of the suggested settings in it (uncommented them). When I create and open a test.py file and do something like a tab, it goes 8 spaces instead of 4.

Not sure what's going wrong.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

I'd replace

au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
fu Select_c_style()
    if search('^\t', 'n', 150)
        set shiftwidth=8
        set noexpandtab
    el 
        set shiftwidth=4
        set expandtab
    en
endf

with

" indenting
set cindent
set autoindent
set shiftwidth=4
set softtabstop=4
set tabstop=4
set expandtab
set backspace=indent,eol,start

because it is not clear that either the Select_c_style() function is getting called or that the quoted code is enough.

Yes, my second .vimrc extract pretty much prevents you from using tabs anywhere without an explicit Ctrl-V Tab, but literal tabs in most Unixy situations are just an irritant anyway. (and Pythonistas who post .vimrc files with vim abbreviations should be forced to use notepad, but that's a different issue ;)

share|improve this answer
    
Doesn't work, and I'm not sure if this is the problem. I don't know if vim is is reading the plugin at all. –  person Jun 15 '10 at 23:20
    
try script debugging: troubleshootingwiki.org/Debugging_Vim_Scripts –  msw Jun 15 '10 at 23:31
    
s/set/setlocal/ –  Luc Hermitte Jun 16 '10 at 7:54

The short answer is that you should put that file in your ~/.vim/plugin directory rather than in your ~/.vim/ftplugin directory. If you do that, it won't matter what the base name of the file is, but the suffix must be ".vim".

According to the header of your file, it can be sourced at any time and will not affect any files other than Python files. So it is safe to put the file in your ~/.vim/plugin directory where it will be sourced every time you start Vim.

There are three reasons putting py.vimrc in your ~/.vim/ftplugin directory does not work. The first is that the suffix must be ".vim". The second is that the base name of the file must be the same as Vim's name for the file type. For Python, the file type is "python". Therefore, the name of a filetype plugin for Python must be "python.vim". The third reason is that the autocommands in that file are read when the file is sourced, which would be when you open a Python source file (if everything else was correct). Their commands are then ready to be executed the next time you open a Python file.

Lastly, don't change the 'tabstop' setting to 4. Even if you use an indentation of 4, set 'shiftwidth' to 4 and maybe 'softtabstop' to 4, but leave 'tabstop' at 8. The reason is that the last time I checked, the Python interpreter assumes tab stops of 8. If you're careful and consistent, you can get away with using other 'tabstop' values, but I think it's risky.

share|improve this answer
    
You're right about ftplugin naming policies and about global changes (the OP is using :set instead of :setlocal). However, as these settings are meant for python editing, they shall be inside a ftplugin. –  Luc Hermitte Jun 16 '10 at 6:06
    
If he uses that file unchanged, it can't be an ftplugin. As an example, assume he does use that file as an ftplugin, then edits some file foo.py. Vim will generate a BufRead event which will trigger the autocommand in $VIMRUNTIME/filetype.vim matching *.py which will then generate a FileType event for "python" and source his file. The second command of that file is "au BufRead,BufNewFile *.py,*pyw set shiftwidth=4". That will enable the autocommand but not execute the "set shiftwidth". The "set shiftwidth" will not be executed until he loads a second python file. –  garyjohn Jun 16 '10 at 15:35

Are you setting filetype plugin on? You might need to do that rather than just filetype plugin indent on.

share|improve this answer
    
filetype plugin indent on implies filetype plugin on –  Luc Hermitte Jun 16 '10 at 6:00
    
ah, here it is, :help :filetype-overview –  intuited Jun 16 '10 at 6:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.