Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable syntax highlighting for CUDA .cu and .cuh files in Vim?

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.

like image 504
Hailiang Zhang Avatar asked Oct 29 '12 20:10

Hailiang Zhang


People also ask

How do I turn on syntax highlighting in Vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

What Is syntax on in Vimrc?

Syntax highlighting is nothing but a feature of vi/vim text editors that displays text, especially source code, in different colors and fonts according to the category of terms. The following instructions show you how to enable or disable syntax colors for VI/VIM text editor running on a Linux or Unix-like system.


2 Answers

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!

like image 116
BenjiWiebe Avatar answered Sep 26 '22 02:09

BenjiWiebe


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
like image 40
Emo Mosley Avatar answered Sep 25 '22 02:09

Emo Mosley