Nakrule
Nakrule

Reputation: 609

How to automaticaly set VIM file type?

I like to create my own documentation using the VIM help page syntax. When I open a file with VIM, I must use the command set filetype=help to switch from plain text to a help page colored syntax (see picture below). How can I tell VIM to set the filetype automatically for my help file ? Is it possible to use a special file extension or to add something in the beginning of the file ?

enter image description here

Upvotes: 3

Views: 2200

Answers (2)

bitifet
bitifet

Reputation: 3679

You can use a modeline:

" vim: set ft=help:

...or, of course, configure some extensions like @alex pointed out.

But in this case I would rather prefer this approach in order to make the files more portable.

Upvotes: 5

alex
alex

Reputation: 490637

Try this in your .vimrc.

au BufRead,BufNewFile *.txt set filetype=help

This will do all txt files though, but you can change it above if you want to target more specific filenames.

Upvotes: 6

Related Questions