> I have a bunch of these executable scripts, with shebang lines, and I
> want configure vim to detect the filetype using the shebang line. The
> problem is that these scripts all must have the .foo extension
> (they're run automatically by a build system), and the system-wide
> filetype.vim recognizes .foo files as having a particular filetype,
> which is not the one I want. Therefore, vim thinks it knows what kind
> of files these are and never reads the shebang line.
>
> How can I configure vim so that this incorrect recognition stops
> happening? Basically, I want things so that when I open a .foo file,
> it identifies the filetype only from the shebang line.
>
> I tried using an autocmd to ignore the incorrect filetype:
>
> autocmd BufNewFile,BufRead *.foo set filetype=ignored
>
> But this leaves the files without any useful filetype at all. I
> suspect that I need to somehow unset the filetype and then tell vim to
> set it only from scripts.vim. However, I have no idea how to do this.
> Any help would be much appreciated.
Create a file ~/.vim/scripts.vim and put something like this inside:
if did_filetype()
finish
endif
if getline(1) =~ '^#!'
setfiletype sh
endif
You might need to adjust the setfiletype line to match your preferred
filetype and also the detection can possibly be made more strict to fit
your example.
See also the help at:
:h new-filetype-scripts
:h new-filetype
regards,
Christian
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment