12

How do I make vim automatically apply c++ syntax highlight on Arduino files (.ino/.pde)?

Or how does vim syntax highlight know what is a c++ file? And how can I tell him that files that is called .ino and .pde is also c++ files.

3 Answers 3

17

Add something like this to ~/.vimrc:

autocmd BufNewFile,BufReadPost *.ino,*.pde set filetype=cpp

Or more correctly, to ~/.vim/ftdetect/cpp.vim.

4

Vim searches for syntax files named {name}.vim where name represents the language, for example cpp.vim for c++ files. If you want that an .ino file has his own syntax highlight create a file called ~/.vim/syntax/ino.vim and you can start use it with :set syntax=ino. In your case you can create a link to a cpp.vim file.

ln -s /usr/share/vim/vimcurrent/syntax/cpp.vim ~/.vim/syntax/ino.vim

3

You can create an autocommand as follows:

au BufRead,BufNewFile *.pde,*.ino set filetype=c++

Put this into your .vimrc to make the setting persistent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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