Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

GNU Octave and Matlab share the .m suffix, but Octave's syntax is a little different, like allowing # as a comment.

I created a scripts.vim, but that does not get called since the filetype is already set to Matlab.

That is the snippet that I use, it works, but it never gets executed in ~/.vim/scripts.vim or if I put it into ~/.vim/ftdetect/octave.vim

if getline(1) =~ '^#!/.*octave'                                        
    set filetype=octave

Where can I set this code?

share|improve this question
up vote 0 down vote accepted

I got it to work with the filetype.vim now:

" ~/.vim/filetype.vim

if exists("did_load_filetypes")

function! DetectOctave()
    echom getline(1)
    if getline(1) =~ '^#!/.*octave.*'                                        
        set filetype=octave

augroup filetypedetect
    au! BufRead,BufNewFile *.m  call DetectOctave()
augroup END
share|improve this answer
Please mark this answer correct so people will know the problem has been solved. – Scott Wilson Mar 14 '12 at 19:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.