Syntax highlighting for CUDA in Vim


Vim has had syntax highlighting support for CUDA source files for a long time now. You can check this: open any .cu file and try the command :set filetype?. You will see that Vim knows that it is a CUDA source file. It applies the syntax highlighting from the file /usr/share/vim/vim74/syntax/cuda.vim.

So, what is the problem? The syntax highlighting done by Vim for CUDA is very very minimal. My CUDA source files look like pages of plain white text in Vim! Also, the comments in the cuda.vim file that it was last updated in 2007. Now that is old!

Solution 1

There is an alternate cu.vim or cuda.vim syntax file for Vim floating around on the web. You can get it, for example, from here.

I replaced the cuda.vim that ships with Vim with this one and found it slightly better. But not by much. It still looks like lots of plain text.

Solution 2

The better solution for me was to just syntax highlight CUDA file as C++ file. This gave the best results, with the highest number of elements in the file being colored when compared to above two methods.

To do this, add this line to your .vimrc:

autocmd BufRead,BufNewFile *.cu set filetype=cpp

Tried with: Vim 7.4 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s