├── ftdetect └── vlang.vim ├── CONTRIBUTING.md ├── ftplugin └── vlang.vim ├── .github └── ISSUE_TEMPLATE.md ├── README.md ├── indent └── vlang.vim └── syntax └── vlang.vim /ftdetect/vlang.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.v set filetype=vlang 2 | " Currently used in some directories in the compiler 3 | au BufNewFile,BufRead *.vv set filetype=vlang 4 | " Support for v scripts 5 | au BufNewFile,BufRead *.vsh set filetype=vlang 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | V-Vim is a young project with a lot of room for improvement, so contributions 3 | from the community are more than welcome. 4 | 5 | ## Feature Requests 6 | If you'd like to make an addition to v-vim, please submit a feature request 7 | as an issue and wait for it to be reviewed by a core contributor before 8 | proceeding with any pull requests. Follow the template for feature requests 9 | laid out in the [issue template](.github/ISSUE_TEMPLATE.md). 10 | 11 | ## Pull Requests 12 | Please obey the following guidelines for pull requests: 13 | 1. The branch on your fork should be named for the issue it addresses (i.e. 14 | "VV-123"). You should also link to said issue in the description. 15 | 2. Each pull request should consist of no more than 10 commits. If the number 16 | of commits exceeds this, squash some together. 17 | 3. The description should consist of at least one paragraph detailing what 18 | files/functions you modified to resolve the issue. 19 | 20 | -------------------------------------------------------------------------------- /ftplugin/vlang.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_ftplugin") 2 | finish 3 | endif 4 | 5 | setlocal commentstring=//\ %s 6 | setlocal makeprg=v\ % 7 | 8 | if exists('b:undo_ftplugin') 9 | let b:undo_ftplugin .= "|setlocal commentstring< makeprg<" 10 | else 11 | let b:undo_ftplugin = "setlocal commentstring< makeprg<" 12 | endif 13 | 14 | function! _VFormatFile() 15 | if exists('g:v_autofmt_bufwritepre') && g:v_autofmt_bufwritepre || exists('b:v_autofmt_bufwritepre') && b:v_autofmt_bufwritepre 16 | let substitution = system("v fmt -", join(getline(1, line('$')), "\n")) 17 | if v:shell_error != 0 18 | echoerr "While formatting the buffer via vfmt, the following error occurred:" 19 | echoerr printf("ERROR(%d): %s", v:shell_error, substitution) 20 | else 21 | let [_, lnum, colnum, _] = getpos('.') 22 | %delete 23 | call setline(1, split(substitution, "\n")) 24 | call cursor(lnum, colnum) 25 | endif 26 | endif 27 | endfunction 28 | 29 | if has('autocmd') 30 | augroup v_fmt 31 | autocmd BufWritePre *.v call _VFormatFile() 32 | augroup END 33 | endif 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Issues 2 | Please read thoroughly before submitting an issue. 3 | 4 | --- 5 | 6 | ## Bug Reports 7 | Before filing a bug report, make sure to search for existing issues to make 8 | sure it hasn't been reported already. If it hasn't, follow the format below to 9 | file a new issue: 10 | 11 | ### Summary 12 | Bug report in one concise sentence. 13 | 14 | ### Steps to reproduce 15 | How to reproduce the issue. Things you should mention include: 16 | - Vim version 17 | - Vim variables and settings during error 18 | - Relevant portions of your vimrc 19 | - Other plugins you have installed, particularly ones that may affect the issue 20 | at hand. 21 | 22 | ### Expected Behavior 23 | Describe what you expected to see. 24 | 25 | ### Observed Behavior 26 | Explain how vim actually behaved. Consider including screenshots if necessary. 27 | 28 | --- 29 | 30 | ## Feature Requests 31 | As with bug reports, please search existing issues to make sure your idea is 32 | original. If it is, follow the format below to file a new issue: 33 | 34 | ### Summary 35 | Describe your idea in one concise sentence. 36 | 37 | ### Explanation 38 | Explain in detail how your proposed feature would improve v-vim. Mention how it 39 | would fix the existing shortcomings of v-vim if applicable. 40 | 41 | ### Implementation 42 | Suggest how the proposed feature would be implemented, if possible. You don't 43 | have to have all the details down, just a summary of what files need to be 44 | created or altered. 45 | 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Support for V in Vim 2 | The files in this repository provide support for the [v programming language](https://vlang.io) in Vim. 3 | 4 | ## Installation 5 | 6 | ### Using a Plugin Manager 7 | 8 | You can install V support with a vim plugin manager as usual, for example with [Plug](https://github.com/junegunn/vim-plug): 9 | 10 | ```vim 11 | Plug 'ollykel/v-vim' 12 | 13 | ``` 14 | Reload config (or save & exit vim/neovim), then: 15 | 16 | ```vim 17 | :PlugInstall 18 | ``` 19 | 20 | ## Options 21 | You can add any of the following into your vim config to disable highlighting. 22 | The following options are enabled by default: 23 | 24 | ```vim 25 | " Disable highlight white space after "[]". 26 | let g:v_highlight_array_whitespace_error = 0 27 | 28 | " Disable highlight white space around the communications operator that don't follow the standard style. 29 | let g:v_highlight_chan_whitespace_error = 0 30 | 31 | " Disable highlight instances of tabs following spaces. 32 | let g:v_highlight_space_tab_error = 0 33 | 34 | " Disable highlight trailing white space. 35 | let g:v_highlight_trailing_whitespace_error = 0 36 | 37 | " Disable highlight function calls. 38 | let g:v_highlight_function_calls = 0 39 | 40 | let g:v_highlight_fields = 0 41 | ``` 42 | 43 | You can add any of the following to your vim config to enable aditional options. 44 | The following options are disabled by default: 45 | ```vim 46 | " Enable automatically formatting file via "v fmt -" before writing buffer. 47 | let g:v_autofmt_bufwritepre = 1 48 | ``` 49 | -------------------------------------------------------------------------------- /indent/vlang.vim: -------------------------------------------------------------------------------- 1 | " Based on the Go identation file. 2 | " 3 | " Copyright 2011 The Go Authors. All rights reserved. 4 | " Use of this source code is governed by a BSD-style 5 | " license that can be found in the LICENSE file. 6 | 7 | if exists("b:did_indent") 8 | finish 9 | endif 10 | let b:did_indent = 1 11 | 12 | setlocal nolisp 13 | setlocal autoindent 14 | setlocal indentexpr=VlangIndent(v:lnum) 15 | setlocal indentkeys+=<:>,0=},0=) 16 | setlocal noexpandtab 17 | 18 | if exists("*VlangIndent") 19 | finish 20 | endif 21 | 22 | let s:cpo_save = &cpo 23 | set cpo&vim 24 | 25 | function! VlangIndent(lnum) abort 26 | let prevlnum = prevnonblank(a:lnum-1) 27 | if prevlnum == 0 28 | return 0 29 | endif 30 | 31 | let prevl = substitute(getline(prevlnum), '//.*$', '', '') 32 | let thisl = substitute(getline(a:lnum), '//.*$', '', '') 33 | let previ = indent(prevlnum) 34 | 35 | let ind = previ 36 | 37 | if prevl =~ '[({]\s*$' 38 | " previous line opened a block 39 | let ind += shiftwidth() 40 | endif 41 | if prevl =~# '^\s*\(case .*\|default\):$' 42 | " previous line is part of a switch statement 43 | let ind += shiftwidth() 44 | endif 45 | 46 | if thisl =~ '^\s*[)}]' 47 | " this line closed a block 48 | let ind -= shiftwidth() 49 | endif 50 | 51 | " Colons are tricky. 52 | " We want to outdent if it's part of a switch ("case foo:" or "default:"). 53 | " We ignore trying to deal with jump labels because (a) they're rare, and 54 | " (b) they're hard to disambiguate from a composite literal key. 55 | if thisl =~# '^\s*\(case .*\|default\):$' 56 | let ind -= shiftwidth() 57 | endif 58 | 59 | return ind 60 | endfunction 61 | 62 | " restore Vi compatibility settings 63 | let &cpo = s:cpo_save 64 | unlet s:cpo_save 65 | 66 | " vim: sw=2 ts=2 et 67 | -------------------------------------------------------------------------------- /syntax/vlang.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: V 3 | " Maintainer: Oliver Kelton (https://github.com/ollykel) 4 | " Last Change: 2019 Jun 13 5 | " NOTE: largely based on go.vim, maintained by David Barnett 6 | " see David Barnett (https://github.com/google/vim-ft-go) 7 | " Options: 8 | " There are some options for customizing the highlighting; the recommended 9 | " settings are the default values, but you can write: 10 | " let OPTION_NAME = 0 11 | " in your ~/.vimrc file to disable particular options. You can also write: 12 | " let OPTION_NAME = 1 13 | " to enable particular options. At present, all options default to on. 14 | " 15 | " - g:v_highlight_array_whitespace_error 16 | " Highlights white space after "[]". 17 | " - g:v_highlight_chan_whitespace_error 18 | " Highlights white space around the communications operator that don't 19 | " follow the standard style. 20 | " Highlights commonly used library types (io.Reader, etc.). 21 | " - g:v_highlight_space_tab_error 22 | " Highlights instances of tabs following spaces. 23 | " - g:v_highlight_trailing_whitespace_error 24 | " Highlights trailing white space. 25 | 26 | " Quit when a (custom) syntax file was already loaded 27 | if exists('b:current_syntax') 28 | finish 29 | endif 30 | 31 | if !exists('g:v_highlight_array_whitespace_error') 32 | let g:v_highlight_array_whitespace_error = 1 33 | endif 34 | if !exists('g:v_highlight_chan_whitespace_error') 35 | let g:v_highlight_chan_whitespace_error = 1 36 | endif 37 | if !exists('g:v_highlight_space_tab_error') 38 | let g:v_highlight_space_tab_error = 1 39 | endif 40 | if !exists('g:v_highlight_trailing_whitespace_error') 41 | let g:v_highlight_trailing_whitespace_error = 1 42 | endif 43 | if !exists('g:v_highlight_function_calls') 44 | let g:v_highlight_function_calls = 1 45 | endif 46 | if !exists('g:v_highlight_fields') 47 | let g:v_highlight_fields = 1 48 | endif 49 | 50 | syn case match 51 | 52 | syn match vDeclType "\<\(struct\|interface\|type\|enum\)\>" 53 | syn keyword vDeclaration pub mut var const 54 | hi def link vDeclType Keyword 55 | hi def link vDeclaration Keyword 56 | 57 | syn keyword vDirective module import 58 | hi def link vDirective Statement 59 | 60 | syn region vIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 61 | syn match vIncluded display contained "<[^>]*>" 62 | syn match vFlagDefinition display contained "\s\i[^\n]*" 63 | hi def link vIncluded vString 64 | hi def link vFlagDefinition vString 65 | 66 | syn match vInclude display "^\s*\zs\(%:\|#\)\s*include\>\s*["<]" contains=vIncluded 67 | syn match vFlag display "^\s*\zs\(%:\|#\)\s*flag\>\s*[^\n]*" contains=vFlagDefinition 68 | syn region vShebang display start=/^#!/ end=/$/ 69 | hi def link vInclude Include 70 | hi def link vFlag Include 71 | hi def link vShebang Include 72 | 73 | " Keywords within functions 74 | syn keyword vStatement defer go goto return break continue 75 | hi def link vStatement Statement 76 | 77 | syn keyword vConditional if else match or select 78 | hi def link vConditional Conditional 79 | 80 | syn keyword vRepeat for in 81 | hi def link vRepeat Repeat 82 | 83 | syn match vCodeGen /$if\>/ 84 | " XXX Enable when compile-time code-gen is implemented in V 85 | " syn match vCodeGen /\.fields\>/ 86 | " syn match vCodeGen /\.$\i*\>/ 87 | hi def link vCodeGen Identifier 88 | 89 | " Predefined types 90 | syn keyword vType any chan char map bool string error voidptr 91 | syn match vOptionalType "\%(\/ 109 | syn match vDeclaration contained /\/ 110 | 111 | " Predefined functions and values 112 | syn keyword vBuiltins assert C 113 | syn keyword vBuiltins complex exit imag 114 | syn keyword vBuiltins print println eprint eprintln 115 | syn keyword vBuiltins malloc copy memdup isnil 116 | syn keyword vBuiltins panic recover 117 | syn match vBuiltins /\/ 118 | hi def link vBuiltins Keyword 119 | 120 | syn keyword vConstants true false 121 | hi def link vConstants Keyword 122 | 123 | " Comments; their contents 124 | syn keyword vTodo contained TODO FIXME XXX BUG 125 | hi def link vTodo Todo 126 | 127 | syn cluster vCommentGroup contains=vTodo 128 | syn region vComment start="/\*" end="\*/" contains=@vCommentGroup,@Spell 129 | syn region vComment start="//" end="$" contains=@vCommentGroup,@Spell 130 | hi def link vComment Comment 131 | 132 | " V escapes 133 | syn match vStringVar display contained +\$[0-9A-Za-z\._]*\([(][^)]*[)]\)\?+ 134 | syn match vStringVar display contained "\${[^}]*}" 135 | syn match vStringSpeChar display contained +\\[abfnrtv\\'"`]+ 136 | syn match vStringX display contained "\\x\x\{1,2}" 137 | syn match vStringU display contained "\\u\x\{4}" 138 | syn match vStringBigU display contained "\\U\x\{8}" 139 | syn match vStringError display contained +\\[^0-7xuUabfnrtv\\'"]+ 140 | 141 | hi def link vStringVar Special 142 | hi def link vStringSpeChar Special 143 | hi def link vStringX Special 144 | hi def link vStringU Special 145 | hi def link vStringBigU Special 146 | hi def link vStringError Error 147 | 148 | " Characters and their contents 149 | syn cluster vCharacterGroup contains=vStringSpeChar,vStringVar,vStringX,vStringU,vStringBigU 150 | syn region vCharacter start=+`+ end=+`+ contains=@vCharacterGroup 151 | hi def link vCharacter Character 152 | 153 | " Strings and their contents 154 | syn cluster vStringGroup contains=@vCharacterGroup,vStringError 155 | 156 | syn region vString start=+"+ skip=+\\\\\|\\'+ end=+"+ contains=@vStringGroup 157 | syn region vString start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@vStringGroup 158 | 159 | syn region vRawString start=+r"+ end=+"+ 160 | syn region vRawString start=+r'+ end=+'+ 161 | 162 | hi def link vString String 163 | hi def link vRawString String 164 | 165 | " Regions 166 | syn region vBlock start="{" end="}" transparent fold 167 | syn region vParen start='(' end=')' transparent 168 | 169 | " Integers 170 | syn match vDecimalInt "\<\d\+\([Ee]\d\+\)\?\>" 171 | syn match vOctalInt "\<0o\o\+\>" 172 | syn match vHexInt "\<0x\x\+\>" 173 | syn match vBinaryInt "\<0b[01]\+\>" 174 | syn match vSnakeInt "\<[0-9_]\+\>" 175 | 176 | hi def link vDecimalInt Integer 177 | hi def link vOctalInt Integer 178 | hi def link vHexInt Integer 179 | hi def link vBinaryInt Integer 180 | hi def link vSnakeInt Integer 181 | hi def link Integer Number 182 | 183 | " Floating point 184 | syn match vFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>" 185 | syn match vFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>" 186 | syn match vFloat "\<\d\+[Ee][-+]\d\+\>" 187 | 188 | hi def link vFloat Float 189 | hi def link Float Number 190 | 191 | " Imaginary literals 192 | " XXX Enable when complex numbers are implemented in V 193 | " syn match vImaginary "\<\d\+i\>" 194 | " syn match vImaginary "\<\d\+\.\d*\([Ee][-+]\d\+\)\?i\>" 195 | " syn match vImaginary "\<\.\d\+\([Ee][-+]\d\+\)\?i\>" 196 | " syn match vImaginary "\<\d\+[Ee][-+]\d\+i\>" 197 | " 198 | " hi def link vImaginary Number 199 | 200 | " Generics 201 | syn match vGenericBrackets display contained "[<>]" 202 | syn match vInterfaceDeclaration display "\s*\zsinterface\s*\i*\s*<[^>]*>" contains=vDeclType,vGenericBrackets 203 | syn match vStructDeclaration display "\s*\zsstruct\s*\i*\s*<[^>]*>" contains=vDeclType,vGenericBrackets 204 | " vFunctionName only appears when v_highlight_function_calls set 205 | syn match vFuncDeclaration display "\s*\zsfn\s*\i*\s*<[^>]*>" contains=vFunctionName,vDeclaration,vGenericBrackets 206 | 207 | hi def link vGenericBrackets Identifier 208 | 209 | " Spaces after "[]" 210 | if v_highlight_array_whitespace_error != 0 211 | syn match vSpaceError display "\(\[\]\)\@<=\s\+" 212 | endif 213 | 214 | " Spacing errors around the 'chan' keyword 215 | if v_highlight_chan_whitespace_error != 0 216 | " receive-only annotation on chan type 217 | syn match vSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@=" 218 | " send-only annotation on chan type 219 | syn match vSpaceError display "\(\ ) OR 252 | " - The symbols: \n \r space OR 253 | " - The symbols: , : . 254 | " 3. Have the start of highlight (hs) be the start of matched 255 | " pattern (s) offsetted one to the right (+1) (see :h E401) 256 | syn match vField /\.\w\+\ 257 | \%(\%([\/\-\+*%]\)\|\ 258 | \%([\[\]{}<\>\)]\)\|\ 259 | \%([\!=\^|&]\)\|\ 260 | \%([\n\r\ ]\)\|\ 261 | \%([,\:.]\)\)\@=/hs=s+1 262 | endif 263 | hi def link vField Identifier 264 | 265 | " Search backwards for a global declaration to start processing the syntax. 266 | "syn sync match vSync grouphere NONE /^\(const\|var\|type\|func\)\>/ 267 | 268 | " There's a bug in the implementation of grouphere. For now, use the 269 | " following as a more expensive/less precise workaround. 270 | syn sync minlines=500 271 | 272 | let b:current_syntax = 'vlang' 273 | 274 | " vim: sw=2 sts=2 et 275 | --------------------------------------------------------------------------------