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.

Sekhemty
  • 9,916
Johan
  • 5,515

3 Answers3

17

Add something like this to ~/.vimrc:

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

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

Thor
  • 6,763
  • 1
  • 40
  • 44
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

mg.
  • 143
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.

Marco
  • 4,444