Skip to content

Commit d7823de

Browse files
committed
update rust.vim to hilight foo::bar and more
1 parent e776047 commit d7823de

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/etc/vim/syntax/rust.vim

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ syn keyword rustKeyword check claim cont const copy else export extern fai
2020
syn keyword rustKeyword for if impl import in let log
2121
syn keyword rustKeyword loop mod mut of pure
2222
syn keyword rustKeyword ret self to unchecked
23-
syn keyword rustKeyword unsafe use while with
23+
syn match rustKeyword "unsafe" " Allows also matching unsafe::foo()
24+
syn keyword rustKeyword use while with
2425
" FIXME: Scoped impl's name is also fallen in this category
2526
syn keyword rustKeyword mod iface trait class enum type nextgroup=rustIdentifier skipwhite
2627
syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite
@@ -36,9 +37,19 @@ syn keyword rustType f64 i8 i16 i32 i64 str
3637

3738
syn keyword rustBoolean true false
3839

39-
syn match rustItemPath "\(\w\|::\)\+"
40+
syn keyword rustConstant some none " option
41+
" syn keyword rustConstant left right " either
42+
" syn keyword rustConstant ok err " result
43+
" syn keyword rustConstant success failure " task
44+
" syn keyword rustConstant cons nil " list
45+
" syn keyword rustConstant empty node " tree
4046

41-
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+
47+
" If foo::bar changes to foo.bar, change this ("::" to "\.").
48+
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
49+
syn match rustModPath "\w\(\w\)*::"he=e-2,me=e-2
50+
syn match rustModPathSep "::"
51+
52+
syn region rustString start=+L\="+ skip=+\\\\\|\\"+ end=+"+
4253

4354
syn region rustAttribute start="#\[" end="\]" contains=rustString
4455

@@ -72,21 +83,25 @@ syn keyword rustTodo TODO FIXME XXX NB
7283
hi def link rustHexNumber rustNumber
7384
hi def link rustBinNumber rustNumber
7485

75-
" Recommend changing rustAssert to something else - I use ctermfg=yellow.
7686
hi def link rustString String
7787
hi def link rustCharacter Character
7888
hi def link rustNumber Number
7989
hi def link rustBoolean Boolean
90+
hi def link rustConstant Constant
8091
hi def link rustFloat Float
8192
hi def link rustAssert Keyword
8293
hi def link rustKeyword Keyword
8394
hi def link rustIdentifier Identifier
95+
hi def link rustModPath Include
8496
hi def link rustFuncName Function
8597
hi def link rustComment Comment
8698
hi def link rustMacro Macro
8799
hi def link rustType Type
88100
hi def link rustTodo Todo
89101
hi def link rustAttribute PreProc
102+
" Other Suggestions:
103+
" hi def link rustModPathSep Conceal
104+
" hi rustAssert ctermfg=yellow
90105

91106
syn sync minlines=200
92107
syn sync maxlines=500

0 commit comments

Comments
 (0)