rausted
rausted

Reputation: 959

VIM filetype plugin does not take expandtab option

Here's my .vimrc what I expect is expandtab to work on every mentioned filetype, except make where it is explicitly disabled. et used to work as a non-filetype set command, but detecting the filetype is important.

" vundle Config
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'vim-syntastic/syntastic'
Plugin 'Shougo/vimproc'
" All of your Plugins must be added before the following line
call vundle#end()

filetype on
filetype plugin on
filetype indent on

" Remove whitespace
autocmd BufWritePre * %s/\s\+$//e
autocmd FileType cpp,html,css set et paste tabstop=4 shiftwidth=4 backspace=2 matchpairs+=<:>
autocmd FileType haskell,go,js,erlang,vim,tex set et paste tabstop=4 shiftwidth=4 backspace=2
autocmd FileType make set noexpandtab paste shiftwidth=8 softtabstop=0
syntax on

What I observe is that some options are set, some are not. The expandtab is the one that I can't get to work specifically. Here's the output of :set when opening my .vimrc file (filetype=vim).

backspace=2         filetype=vim        keywordprg=:help    paste               shiftwidth=4        tabstop=4           ttymouse=sgr
commentstring="%s   helplang=en         laststatus=2        scroll=21           syntax=vim          ttyfast

Upvotes: 1

Views: 156

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172768

Ah, that's a tricky one. Have a look at :help 'paste':

When the 'paste' option is switched on (also when it was already on):

  • mapping in Insert mode and Command-line mode is disabled
  • abbreviations are disabled
  • 'autoindent' is reset
  • 'expandtab' is reset
  • [...]

Note how the option is introduced:

This is useful if you want to cut or copy some text from one window and paste it in Vim.

This option only is meant to be temporarily enabled when pasting into the terminal. Usually via a key configured in the 'pastetoggle' option. (GVIM doesn't need it; it can detect pastes. If you have X selection and clipboard enabled, you can also use the * and + registers instead.)

additional comments

  • The three :filetype commands can be condensed into a single filetype plugin indent on.
  • If you put this around your :autocmds, you'll remove the risk that some plugin clobbers them, and you can also safely reload your ~/.vimrc without defining duplicates:
augroup myCustomizations
autocmd!
autocmd ...
augroup END

Upvotes: 3

Related Questions