15

I found that my ~/.vimrc file has syntax on but it didn't work for any CUDA file (.cu).

Not sure to how to do it.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Hailiang Zhang
  • 17,604
  • 23
  • 71
  • 117

4 Answers4

18

Add these two lines to ~/.vimrc:

au BufNewFile,BufRead *.cu set ft=cuda
au BufNewFile,BufRead *.cuh set ft=cuda

And put cuda.vim in ~/.vim/syntax/

Have fun!

Zheng Qu
  • 781
  • 6
  • 22
BenjiWiebe
  • 2,116
  • 5
  • 22
  • 41
11

Sounds like you might be missing the syntax highlighting file for vim. You should check your /usr/share/vim/vim70/syntax directory for cuda.vim. That directory will vary depending on your system and version of vim.

If your version of vim does not come with cuda.vim, you can download this cuda.vim file and place it in ~/.vim/syntax/.

Update: add the following lines in your ~/.vimrc as @BenjiWiebe recommended:

au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.cuh set filetype=cuda
Zheng Qu
  • 781
  • 6
  • 22
Emo Mosley
  • 525
  • 3
  • 9
3

how about that, does this work ?

cd /usr/share/vim/vim*/syntax
sudo cp cpp.vim cu.vim
echo "au BufNewFile,BufRead *.cu set ft=cu" >> ~/.vimrc
pjam
  • 6,356
  • 5
  • 30
  • 40
1

It's been long since the question was originally asked, but I found myself having almost the same issue and not being able to solve it by following the previous answers.

In my case, vim would automatically highlight .cu files (I'm using vim 80, which already has cuda.vim in /usr/share/vim/vim80/syntax/), but ignore .cuh ones. To solve this, I edited /usr/share/vim/vim80/filetype.vim and added

au BufNewFile,BufRead *.cuh         setf cuda

And that was it!

pamgur
  • 83
  • 1
  • 8