Set filetype for specific file?

14 lượt xem
Chuyển tới thư đầu tiên chưa đọc

Ven Tadipatri

chưa đọc,
13:44:31 30 thg 9, 201930/9/19
đến vim...@googlegroups.com
Is there a way to set the file type permanently for a specific file
(not based on extension)?
For example, if I have a file ~/dir/myfile.properties, I'd like to
always set the filetype to be sql, without having to run :set
filetype=sql every time I open the file.

Thanks,
Ven

Gary Johnson

chưa đọc,
13:58:53 30 thg 9, 201930/9/19
đến vim...@googlegroups.com
The easiest way is to create a file in your ~/.vim/ftdetect
directory. I don't think the name matters except perhaps for ending
in .vim. Put this line in that file.

au BufRead,BufNewFile ~/dir/myfile.properties set filetype=sql

For more on this, see:

:help new-filetype

Regards,
Gary

Pete Doherty

chưa đọc,
19:04:11 30 thg 9, 201930/9/19
đến vim_use
Have you tried something like the following?

`autocmd BufNewFile,BufRead ~/foo.bar set filetype=myfiletype`

Tony Mechelynck

chưa đọc,
19:19:17 30 thg 9, 201930/9/19
đến Ven Tadipatri, vim_use
See :help modeline

For instance, add near the top or bottom of the file a line with either

-- vim: ft=sql
(modeline form 1, which goes to the end of the line)

or

/* vim: set ft=sql :*/
(modeline form 2, which can be followed by a colon and then anything,
such as a comment terminator)

as an SQL comment, and optionally with additional options to be set
for that file as with :setlocal. Anything is allowed before the "
vim:" modeline leader; usually a comment leader for the current
language is placed there.

Best regards,
Tony.
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới