Rob Howard
Rob Howard

Reputation: 1819

Selectively disabling 'filetype plugin indent' for particular filetypes in Vim 7.3

I have vim 7.3, with the setup that's provided with Ubuntu 11.04 by default. My .vimrc looks like the following:

set nocompatible
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab

filetype plugin indent on
let g:omni_sql_no_default_maps = 1 " Stops Omni from grabbing left/right keys

" syntax, colorscheme and status line directives omitted.

How do I selectively disable this indentation for different filetypes (eg. php, phtml, rb)?

So far I've tried autocmd FileType php filetype plugin indent off and a few variants, but I haven't had much luck yet.

(Removing the filetype plugin ... line produces the desired behaviour, but obviously affects all filetypes instead of just a few.)

Upvotes: 7

Views: 5334

Answers (3)

clime
clime

Reputation: 8885

The Prince's suggestion with autocmd does not work for me. This does:

filetype plugin on
autocmd BufRead,BufNewFile * filetype indent off
autocmd BufRead,BufNewFile *.py filetype indent on

Enables filetype indent on selectively for python files. It's pretty cool to have also set ai because it works for files with indent off as a fallback.

Upvotes: 6

etuardu
etuardu

Reputation: 5536

Note that disabling filetype indent is likely not what you want:

    :filetype indent off

[...] This actually loads the file "indoff.vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

If you want, just like suggested by this online help, to disable indenting options for some filetypes, you could put this in your .vimrc:

filetype plugin indent on
au filetype php,phtml,rb call DisableIndent()

function! DisableIndent()
        set autoindent&
        set cindent&
        set smartindent&
        set indentexpr&
endfunction

Also, make sure to understand what these options you are turning off are by consulting the online help (e.g. :help autoindent).

Upvotes: 6

Prince Goulash
Prince Goulash

Reputation: 15735

All the filetype indent on command does is to source $VIMRUNTIME/indent.vim, which itself switches on filetype and calls the individual $VIMRUNTIME/indent/[type].vim. So you could modify the default indent.vim to ignore certain filetypes (or save a modified version of this file locally at .vim/indent.vim).

If you are unhappy with that you could try setting the plugin/indent behaviour in your vimrc separately:

filetype plugin on
au FileType c,vim,lisp filetype indent on

(and of course add the relevant filetypes). This works for me.

Upvotes: 4

Related Questions