Skip to content

Instantly share code, notes, and snippets.

@jam1garner
Created September 21, 2021 01:54
Show Gist options
  • Save jam1garner/181b089602f24a2872611a7e006736c8 to your computer and use it in GitHub Desktop.
Save jam1garner/181b089602f24a2872611a7e006736c8 to your computer and use it in GitHub Desktop.
A slightly better version of Rust attribute highlighting in vim

A vim script for making the Rust attribute highlighting a tiny bit better

Install

Neovim

Copy the file to '~/.config/nvim/after/syntax/rust.vim'

Vim

Copy the file to '~/.vim/after/syntax/rust.vim'

syn region rustAttribute start="#!\?\[" end="\]" contains=CONTAINED
syn region rustFuncAttribute start="#!\?\[\_s*\w\+\_s*(" end=")\_s*\]" contains=rustAttributeContents keepend
syn match rustSimpleAttribute "#!\?\[\_s*\w\+\_s*\]"
syn region rustDeriveAttribute start="#!\?\[\_s*derive\_s*(" end=")\_s*\]" keepend
syn region rustAttributeContents matchgroup=rustAttributeParens start="(" end=")" contains=CONTAINED contained
syn region rustAttributeBalance start="(" end=")" containedin=rustAttributeContents contained contains=TOP
syn region rustAttributeBalance start="\[" end="\]" containedin=rustAttributeContents contained contains=CONTAINED
hi def link rustSimpleAttribute Define
hi def link rustFuncAttribute Define
hi def link rustDeriveAttribute Define
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment