From fb276f7fb0e952b94f3207c3694546075d8806f9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 21:48:06 +0300 Subject: [PATCH] editors: push syntax highlighting to vim and neovim (fixes #10321) --- README.md | 1 + editors/vim/README.md | 23 ++++++++++++++ editors/vim/ftdetect/v.vim | 6 ++++ editors/vim/ftplugin/v.vim | 12 ++++++++ editors/vim/syntax/v.vim | 61 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 editors/vim/README.md create mode 100644 editors/vim/ftdetect/v.vim create mode 100644 editors/vim/ftplugin/v.vim create mode 100644 editors/vim/syntax/v.vim diff --git a/README.md b/README.md index 5e396360e..2a401c034 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,7 @@ shell/editor after that, so that it can pick up the new PATH variable. - [JetBrains](https://plugins.jetbrains.com/plugin/20287-vlang/docs/syntax-highlighting.html) - [Sublime Text 3](https://github.com/vlang/awesome-v#sublime-text-3) - [Vim](https://github.com/vlang/awesome-v#vim) +- [Vim/Neovim Runtime Files](editors/vim) - [VS Code](https://marketplace.visualstudio.com/items?itemName=VOSCA.vscode-v-analyzer) - [zed](https://github.com/lv37/zed-v) diff --git a/editors/vim/README.md b/editors/vim/README.md new file mode 100644 index 000000000..995ceb5cf --- /dev/null +++ b/editors/vim/README.md @@ -0,0 +1,23 @@ +# V Vim/Neovim runtime files + +This directory contains official V runtime files for Vim and Neovim: + +- `ftdetect/v.vim` +- `ftplugin/v.vim` +- `syntax/v.vim` + +## Install in Vim + +```sh +mkdir -p ~/.vim/pack/vlang/start +ln -s /path/to/v/editors/vim ~/.vim/pack/vlang/start/vlang +``` + +## Install in Neovim + +```sh +mkdir -p ~/.local/share/nvim/site/pack/vlang/start +ln -s /path/to/v/editors/vim ~/.local/share/nvim/site/pack/vlang/start/vlang +``` + +Restart Vim/Neovim after installation. diff --git a/editors/vim/ftdetect/v.vim b/editors/vim/ftdetect/v.vim new file mode 100644 index 000000000..ab6cf6f64 --- /dev/null +++ b/editors/vim/ftdetect/v.vim @@ -0,0 +1,6 @@ +" Vim filetype detection for the V language. + +augroup v_filetypedetect + autocmd! + autocmd BufRead,BufNewFile *.v,*.vsh,*.vv setfiletype v +augroup END diff --git a/editors/vim/ftplugin/v.vim b/editors/vim/ftplugin/v.vim new file mode 100644 index 000000000..8480f6ac2 --- /dev/null +++ b/editors/vim/ftplugin/v.vim @@ -0,0 +1,12 @@ +" Vim filetype plugin for the V language. + +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +setlocal commentstring=//\ %s +setlocal comments=s1:/*,mb:*,ex:*/,:// +setlocal suffixesadd=.v,.vsh + +let b:undo_ftplugin = 'setlocal commentstring< comments< suffixesadd<' diff --git a/editors/vim/syntax/v.vim b/editors/vim/syntax/v.vim new file mode 100644 index 000000000..310170c5e --- /dev/null +++ b/editors/vim/syntax/v.vim @@ -0,0 +1,61 @@ +" Vim syntax file +" Language: V +" Maintainer: V contributors + +if exists('b:current_syntax') + finish +endif + +syn case match + +syn keyword vTodo TODO FIXME XXX NOTE BUG contained +syn match vComment +//.*$+ contains=vTodo,@Spell +syn region vComment start='/\*' end='\*/' contains=vTodo,@Spell + +syn region vString start=+r'+ end=+'+ +syn region vString start=+c'+ skip=+\\\\\|\\'+ end=+'+ contains=vEscape,vInterpolation +syn region vString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=vEscape,vInterpolation +syn region vChar start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=vEscape + +syn match vEscape +\\[abfnrtv'"`\\$]+ contained +syn match vEscape +\\x[0-9A-Fa-f]\{2}+ contained +syn match vEscape +\\u[0-9A-Fa-f]\{4}+ contained +syn region vInterpolation start=+\${+ end=+}+ contained contains=vComptime,vNumber,vString,vChar,vOperator + +syn match vNumber /\v<0x[0-9A-Fa-f_]+>/ +syn match vNumber /\v<0b[01_]+>/ +syn match vNumber /\v<0o[0-7_]+>/ +syn match vNumber /\v<\d[\d_]*\.\d[\d_]*([eE][+-]?\d[\d_]*)?>/ +syn match vNumber /\v<\d[\d_]*([eE][+-]?\d[\d_]*)?>/ + +syn keyword vBoolean true false +syn keyword vConstant none nil +syn keyword vKeyword as asm assert atomic break const continue defer else enum false for fn __global go goto if import in interface is match module mut shared lock rlock none nil return select sizeof isreftype _likely_ _unlikely_ __offsetof struct true type typeof dump or union pub static volatile unsafe spawn implements like ilike +syn keyword vType bool string rune i8 i16 int i64 i128 isize byte u8 u16 u32 u64 u128 usize f32 f64 char map chan any voidptr byteptr charptr + +syn match vComptime /\$[A-Za-z_][A-Za-z0-9_]*/ +syn match vComptime /@[A-Z_][A-Z0-9_]*/ +syn region vAttribute start=/@\[/ end=/\]/ contains=vComptime + +syn match vOperator /::\|:=\|==\|!=\|<=\|>=\|<<=\|>>=\|>>>=\|&&=\|||=\|<<\|>>>\|>>\|&&\|||\|+=\|-=\|\*=\|\/=\|%=\|\^=\||=\|&=\|<-\|++\|--/ +syn match vOperator /[+\-*\/%&|^~!=<>?:]/ + +syn match vFunction /\<[A-Za-z_][A-Za-z0-9_]*\ze\s*(/ + +hi def link vTodo Todo +hi def link vComment Comment +hi def link vString String +hi def link vChar Character +hi def link vEscape SpecialChar +hi def link vInterpolation Special +hi def link vNumber Number +hi def link vBoolean Boolean +hi def link vConstant Constant +hi def link vKeyword Keyword +hi def link vType Type +hi def link vComptime PreProc +hi def link vAttribute PreProc +hi def link vOperator Operator +hi def link vFunction Function + +let b:current_syntax = 'v' -- 2.39.5