Enabling vim file type plugin

5,996

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:
5,996

Related videos on Youtube

person
Author by

person

Updated on September 17, 2022

Comments

  • person
    person over 1 year

    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.

  • person
    person almost 14 years
    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.
  • msw
    msw almost 14 years
  • Luc Hermitte
    Luc Hermitte almost 14 years
    filetype plugin indent on implies filetype plugin on
  • Luc Hermitte
    Luc Hermitte almost 14 years
    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.
  • intuited
    intuited almost 14 years
    ah, here it is, :help :filetype-overview
  • garyjohn
    garyjohn almost 14 years
    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.