Syntax highlighting for CUDA in Vim. Compared to Vim's default CUDA syntax file, it adds highlighting of all CUDA defined:
- types
- enums
- constants
- global variables
- namespaces
- thrust keywords
All keywords are accumulated from the CUDA Toolkit Documentation.
Optionally triple-angle brackets in CUDA kernel calls can be highlighted.
-
Highlighting of the triple angle-brackets in CUDA kernel calls works only when the angle brackets are on the same line. The function name is only highlighted when called without template arguments, i.e.
MyKernel
won't be highlighted inMyKernel<foo, bar><<<grid, threads>>>(data)
. -
CUDA data fields are not highlighted because many keywords have familiar names which could collide with either user-defined variables (like
ptr
,x
,y
), or with C++ standard library types (likefunction
orarray
) and would mess up the highlighting. If you want structure or class member variables appearing after the.
or->
operators highlighted, use for example vim-cpp-modern. -
Functions are not highlighted by default. There are plenty of other Vim syntax plugins that provide this feature for C/C++ files. See for example vim-cpp-modern.
" Enable highlighting of CUDA kernel calls
let g:cuda_kernel_highlight = 1
" Highlight keywords from CUDA Runtime API
let g:cuda_runtime_api_highlight = 1
" Highlight keywords from CUDA Driver API
let g:cuda_driver_api_highlight = 1
" Highlight keywords from CUDA Thrust library
let g:cuda_thrust_highlight = 1
$ cd ~/.vim/pack/git-plugins/start
$ git clone https://github.com/bfrg/vim-cuda-syntax
Note: The directory name git-plugins
is arbitrary, you can pick any other
name. For more details see :help packages
.
Alternatively, use your favorite plugin manager.
I want everything in-between the triple angle-brackets highlighted to get a more distinct highlighting of kernel calls.
Add the following lines to ~/.vim/after/syntax/cuda.vim
(create the file if
it doesn't exist):
syntax match cudaKernelAngles "<<<\_.\{-}>>>"
highlight link cudaKernelAngles Operator
I want the CUDA language extensions (
__device__
,__host__
, etc.) highlighted like the standard C/C++ keywords.
Add the following to ~/.vim/after/syntax/cuda.vim
:
highlight link cudaStorageClass Statement
Distributed under the same terms as Vim itself. See :help license
.