CUDA syntax highlighting for vim

This is a simple configuration file to add CUDA syntax highlighting to Vim.

Add the attached file in the syntax subdirectory of your vim installation ( under linux, it should be in /usr/share/vim/vim*/syntax, under Windows it should be under C:\Program Files\Vim\vim70\syntax).

The file should be renamed cu.vim.

You can modify/create the .vimrc file in your home directory adding this line:

au BufNewFile,BufRead *.cu set ft=cu

or you can add it for all the users by modifying the file filetype.vim in the vim directory, adding these 2 lines:

" CUDA 

au BufNewFile,BufRead *.cu   setf cu

cu.vim.txt (17.3 KB)

Many thanks!

1 Like

I had just renamed cpp.vim and added the keywords. I’m sure this is better. Thanks!

Wonderful! Thanks very much, it works well for me. I love using Vim for CUDA.

What does au do? I can’t get this to work …

This works for my Ubuntu 8.10:

First, I install vim by “sudo apt-get install vim”. Otherwise, the syntax directory won’t be there.

Then create .vimrc file in my home directory and add the following:

au BufNewFile,BufRead *.cu set ft=cu

syntax on

Finally, vim can display the CUDA syntax highlighting.

Hope this helps.

Awesome, thank you!

hacky kate syntax highlighting file at [url=“http://cobol.cs.berkeley.edu:8008/gatoatigrado/public_repos/index.cgi/kate_syntax/”]http://cobol.cs.berkeley.edu:8008/gatoatig...gi/kate_syntax/[/url]

Maybe it will save someone 2 minutes :) place in ~/.kde4/share/apps/katepart/syntax (create the directory if necessary).

Hacks include Jinja 2 “@” for commands, and a function convention I made up: “_s” for sync’d, “_rs” for presync’d, and “_os” for postsync’d. Feel free to tear them out: [url=“http://cobol.cs.berkeley.edu:8008/gatoatigrado/public_repos/index.cgi/kate_syntax/diff/21b08b756f5d/cuda.xml”]http://cobol.cs.berkeley.edu:8008/gatoatig...756f5d/cuda.xml[/url], [url=“http://cobol.cs.berkeley.edu:8008/gatoatigrado/public_repos/index.cgi/kate_syntax/rev/22896b7e4635”]http://cobol.cs.berkeley.edu:8008/gatoatig...ev/22896b7e4635[/url]. I’ll be happy to post any changes.

Cheers,
Nicholas

I believe cuda syntax highlighting is shipping with vim for a while now.

It seems to syntax highlight GridDim, but isnt it supposed to be gridDim? It is easy to fix though.

the file doesn’t higihtlight cudaErrorInvalidValue, but that is also easy to fix.

edit: I see the comment that says not all error codes are included, but it is still inconvenient.

Thanks a lot. Good piece of work.

I prefer using ~/.vim/syntax directory to n /usr/share/vim/vim*/syntax one for Your vim script. It also runs very well.

Can you describe in detail how you put cu.vim into your local directory ~/.vim/syntax and set it accordingly in .vimrc ? :unsure:

I face the problem that I don’t have the root power to put the file or rename the file in the public directory like /usr/share/vim/vim*/syntax

Thank you very much.

hey, could you post it somewhere again or upload the file to the forum? thanks in advice

antonio Lucas

This works great for syntax highlighting. However, it appears I lose the ability to use folds with foldmethod=syntax. Do others see the same problem? Or can it be an issue of my configuration? I use above line to enable it for .cu files, but maybe it interferes with other settings of my rather massive .vimrc? If not, is there a workaround to enable folding? I’m not sufficiently familiar with the guts of vim to debug this issue.

Any help highly appreciated!