Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 260
Rob Howard Avatar asked Sep 07 '11 06:09

Rob Howard


2 Answers

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.

like image 125
clime Avatar answered Nov 12 '22 06:11

clime


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).

like image 6
etuardu Avatar answered Nov 12 '22 05:11

etuardu