VIM: set filetype=txt for every new file [No Name]
I tried all p开发者_JAVA百科ossible 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?
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
All files are considered plain text unless you have file-type detection turned on or explicitly set the file-type. However, Vim lets you set the file-type to any old text, so are you absolutely sure it is not working?
:set filetype=banana
:set filetype?
filetype=banana
Setting the filetype is not going to have any noticable effect unless there is a corresponding file in the ftplugin
Vim directory and Vim does not ship with a txt.vim
file-type file. You could, of couse, add a txt.vim
here but I am not sure what this will gain you over default settings — what special behaviour would you want for text files that you would not want for the default behaviour?
(If you want syntax highlighting (whatever that may mean for text file!) then you will also have to create a txt.vim
file in the syntax
Vim directory.)
What effect are you trying to achieve?
It's actually way simpler than all this. Just put this as one of the first lines in your .vimrc
.
set ft=txt
Whenever opening a new file, the filetype will be set to txt. But if you open a file with an known existing type it will still be overridden no problem.
精彩评论