├── README.md ├── ftdetect └── gomod.vim └── syntax └── gomod.vim /README.md: -------------------------------------------------------------------------------- 1 | # vim-gomod 2 | 3 | The syntax highlight for go.mod. This is copy from vim-go. 4 | 5 | https://github.com/fatih/vim-go/blob/master/syntax/gomod.vim 6 | 7 | ## Usage 8 | 9 | ## Requirements 10 | 11 | ## Installation 12 | 13 | For [vim-plug](https://github.com/junegunn/vim-plug) plugin manager: 14 | 15 | ``` 16 | Plug 'mattn/vim-gomod' 17 | ``` 18 | 19 | ## License 20 | 21 | Same as vim-go. 22 | 23 | ## Author 24 | 25 | Yasuhiro Matsumoto 26 | -------------------------------------------------------------------------------- /ftdetect/gomod.vim: -------------------------------------------------------------------------------- 1 | augroup filetypedetect 2 | au! BufRead,BufNewFile *.mod,*.MOD 3 | au! BufRead,BufNewFile go.mod setfiletype gomod 4 | augroup END 5 | -------------------------------------------------------------------------------- /syntax/gomod.vim: -------------------------------------------------------------------------------- 1 | " gomod.vim: Vim syntax file for go.mod file 2 | " 3 | " Quit when a (custom) syntax file was already loaded 4 | if exists("b:current_syntax") 5 | finish 6 | endif 7 | 8 | syntax case match 9 | 10 | " match keywords 11 | syntax keyword gomodModule module 12 | syntax keyword gomodGo go contained 13 | syntax keyword gomodRequire require 14 | syntax keyword gomodExclude exclude 15 | syntax keyword gomodReplace replace 16 | 17 | " require, exclude, replace, and go can be also grouped into block 18 | syntax region gomodRequire start='require (' end=')' transparent contains=gomodRequire,gomodVersion 19 | syntax region gomodExclude start='exclude (' end=')' transparent contains=gomodExclude,gomodVersion 20 | syntax region gomodReplace start='replace (' end=')' transparent contains=gomodReplace,gomodVersion 21 | syntax match gomodGo '^go .*$' transparent contains=gomodGo,gomodGoVersion 22 | 23 | " set highlights 24 | highlight default link gomodModule Keyword 25 | highlight default link gomodGo Keyword 26 | highlight default link gomodRequire Keyword 27 | highlight default link gomodExclude Keyword 28 | highlight default link gomodReplace Keyword 29 | 30 | " comments are always in form of // ... 31 | syntax region gomodComment start="//" end="$" contains=@Spell 32 | highlight default link gomodComment Comment 33 | 34 | " make sure quoted import paths are higlighted 35 | syntax region gomodString start=+"+ skip=+\\\\\|\\"+ end=+"+ 36 | highlight default link gomodString String 37 | 38 | " replace operator is in the form of '=>' 39 | syntax match gomodReplaceOperator "\v\=\>" 40 | highlight default link gomodReplaceOperator Operator 41 | 42 | " match go versions 43 | syntax match gomodGoVersion "1\.\d\+" contained 44 | highlight default link gomodGoVersion Identifier 45 | 46 | 47 | " highlight versions: 48 | " * vX.Y.Z-pre 49 | " * vX.Y.Z 50 | " * vX.0.0-yyyyymmddhhmmss-abcdefabcdef 51 | " * vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef 52 | " * vX.Y.(Z+1)-0.yyyymmddhhss-abcdefabcdef 53 | " see https://godoc.org/golang.org/x/tools/internal/semver for more 54 | " information about how semantic versions are parsed and 55 | " https://golang.org/cmd/go/ for how pseudo-versions and +incompatible 56 | " are applied. 57 | 58 | 59 | " match vX.Y.Z and their prereleases 60 | syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?" 61 | " ^--- version ---^^------------ pre-release ---------------------^^--------------- metadata ---------------------^ 62 | " ^--------------------------------------- semantic version -------------------------------------------------------^ 63 | 64 | " match pseudo versions 65 | " without a major version before the commit (e.g. vX.0.0-yyyymmddhhmmss-abcdefabcdef) 66 | syntax match gomodVersion "v\d\+\.0\.0-\d\{14\}-\x\+" 67 | " when most recent version before target is a pre-release 68 | syntax match gomodVersion "v\d\+\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\+" 69 | " ^--- version ---^^--- ------ pre-release -----------------^^--------------- metadata ---------------------^ 70 | " ^------------------------------------- semantic version --------------------------------------------------^ 71 | " most recent version before the target is X.Y.Z 72 | syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\+" 73 | " ^--- version ---^^--------------- metadata ---------------------^ 74 | 75 | " match incompatible vX.Y.Z and their prereleases 76 | syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?+incompatible" 77 | " ^------- version -------^^------------- pre-release ---------------------^^--------------- metadata ---------------------^ 78 | " ^------------------------------------------- semantic version -----------------------------------------------------------^ 79 | 80 | " match incompatible pseudo versions 81 | " incompatible without a major version before the commit (e.g. vX.0.0-yyyymmddhhmmss-abcdefabcdef) 82 | syntax match gomodVersion "v[2-9]\{1}\d*\.0\.0-\d\{14\}-\x\++incompatible" 83 | " when most recent version before target is a pre-release 84 | syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\++incompatible" 85 | " ^------- version -------^^---------- pre-release -----------------^^--------------- metadata ---------------------^ 86 | " ^---------------------------------------- semantic version ------------------------------------------------------^ 87 | " most recent version before the target is X.Y.Z 88 | syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\++incompatible" 89 | " ^------- version -------^^---------------- metadata ---------------------^ 90 | highlight default link gomodVersion Identifier 91 | 92 | let b:current_syntax = "gomod" 93 | --------------------------------------------------------------------------------