Vim: How to set preference for custom file types?

4

I can set the custom filetype settings for the know file types using the *.vim files in ftplugin directory, e.g. c.vim for (c, cpp, h, hxx), python.vim etc.

But I want to set the file types for the custom file extension like *.text, *.letter, *.journal etc. I tried using text.vim and so on but that didn't work.

Xolve

Posted 2010-06-27T08:00:13.013

Reputation: 450

Answers

4

You are looking for autocommands. Add a line for each custom file extension in your .vimrc:

au! BufRead,BufNewFile *.ext setfiletype ext

Then you can specify settings for .ext files in ftplugin/ext.vim.

PS: Note that autocommands must be defined inside an augroup.

mrucci

Posted 2010-06-27T08:00:13.013

Reputation: 8 398

5

You are looking for :h new-filetype.

Luc Hermitte

Posted 2010-06-27T08:00:13.013

Reputation: 1 575

Your answer is great but mrucci gave a direct solution. – Xolve – 2010-06-29T14:32:15.227

1Direct, indeed. But incomplete. There exist files dedicated to filetype detection. – Luc Hermitte – 2010-06-29T15:16:23.937