VIM: set filetype=txt for every new file [No Name]

Reman picture Reman · Mar 30, 2011 · Viewed 8.4k times · Source

I tried all possible things to let vim set filetype to 'txt' to all new files I create (in a new tab) but it doesn't work.

This is p.e. what I've read on the web a few times:
au BufRead,BufNewFile *.txt setlocal ft=txt
(to put in _vimrc)
However it doesn't work.

Can anyone help me?

Answer

Curt Nelson picture Curt Nelson · Mar 30, 2011

The following line, added to your .vimrc, will set the filetype to text if it is not already set.

autocmd BufEnter * if &filetype == "" | setlocal ft=text | endif