Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
endif

Where can I set this code?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

" ~/.vim/filetype.vim

if exists("did_load_filetypes")
    finish
endif

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

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

Your Answer

 
discard

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.