• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    Vim Script
  • License
    ISC License
  • Created almost 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Vim plugin that enhances Rust syntax highlighting

vim-rust-syntax-ext

This is a Vim plugin that enhances Rust syntax highlighting – it does nothing else. This means that it is ideally used in conjunction with the official plugin, so that you can get all the latest non-syntax-related features.

Installation

If you don’t have a plugin manager of choice I recommend vim-plug:

Plug 'arzg/vim-rust-syntax-ext'

Why would I use this plugin when the existing Rust syntax highlighting is good enough?

Here is a screenshot of some code using the official plugin, rust.vim:

Some code using the official Rust plugin for Vim

And here is a screenshot using vim-rust-syntax-ext:

The same code using vim-rust-syntax-ext

Features (some of which rust.vim also has)

Sorry for the bad/incorrect/inconsistent code in the following screenshots. After a while you start to run out of fake code ideas …

Note that features which may require colourscheme support to be differentiated from other highlight groups are marked with an asterisk.

vim-rust-syntax-ext highlights function definitions*:

Variable definitions* too, whether they use let, let mut, const, static ref, or are in a tuple destructure pattern:

Struct/enum/union/type alias definitions are also highlighted:

Now that we’re on the subject of types, look at how the type parameter definitions in this screenshot are highlighted the same way other type definitions are:

One of vim-rust-syntax-ext’s most unique features is that it differentiates* between things from your project, things from the standard library, and things from other modules. This feature was inspired by Xcode, which does this for Swift (but by using code analysis, not regular expressions!). Note that the constants and function calls being highlighted the same is just a quirk of the colourscheme I’m using. The same goes for things from other modules and things from the standard library being highlighted the same – you could make them different if you wanted to do so.

You might worry that this would break the highlighting of enum variants such as LocalEnum::Variant, because vim-rust-syntax-ext would think that Variant is a type from a separate module. This is not the case, however:

vim-rust-syntax-ext makes sure that items from the current crate are still highlighted as local items:

Another one of vim-rust-syntax-ext’s unique features is its careful highlighting of punctuation. With my colourscheme, both delimiters and operators are highlighted the same:

To help you tell the two apart I have linked Operator to Statement in the next screenshot, which is also a common practice of many Vim colourschemes. Note how the less than and greater than operators are highlighted as, well, operators, while when they are used to denote a type parameter they are highlighted as delimiters.

Lifetimes have been paid careful attention in vim-rust-syntax-ext. This screenshot shows that lifetimes are highlighted with a similar logic to variables:* ‘special’ lifetimes like 'static and '_ are highlighted as library constants,* lifetime definitions are highlighted like variable definitions* (look at enum Token<'a>), and lifetime usages are highlighted the same way user variable usages are highlighted.*

Field accesses are highlighted as Identifers:

vim-rust-syntax-ext also highlights attributes:

Note for colourscheme authors

I have made sure that it is as easy as possible to take advantage of vim-rust-syntax-ext’s highlighting as a colourscheme designer, by using highlight default link instead of highlight link so that you can override any links this plugin makes. Additionally, as much as possible, every single syntactical element has its own highlight group so that you can be as granular as you want with your adjustments. To give you an idea of what I mean, the let keyword (rsLet) and macros that come with the standard library (rsLibraryMacro) both get their own highlight groups. I didn’t want to make any assumptions, however, so I have linked all of vim-rust-syntax-ext’s highlight groups to the standard ones found in :help group-name. This means, for example, that rsLibraryMacro and rsUserMacro are not differentiated by default.

Here are some of the more important links you may want to customise:

  • rs{User,Crate,Foreign,Library}{Type,Func,Macro,Const}: The Library set of highlight groups is for items from the standard library; the Foreign set of groups is for items from another module; Crate, which by default links to the User groups, is for items accessed by crate::; and User is essentially for everything else. By default the Crate highlight groups link to the User highlight groups. In case I haven’t explained well, some examples of these highlight groups include rsUserType, rsLibraryFunc, and so on.
  • rsUserIdent: There are no Crate, Foreign, etc identifiers because identifiers cannot be exported, meaning all identifers you will see are from the current project.
  • rs{Type,Func,Ident,Lifetime}Def: These highlight groups are used for definitions of various syntactical items. Note that rsTypeDef is linked by default to Typedef, which may not fit with your colourscheme.
  • rs{User,Special}Lifetime: With ‘special’ lifetimes I really mean 'static and '_ – all other lifetimes get rsUserLifetime.
  • rsAttribute: This is applied to #[attributes], including #[derive(...)] for example. Arguably this should link to Macro (since attributes are usually defined with procedural macros), but I personally find it nicer when rsAttribute is highlighted as a keyword.

Todo

  • r# ... # syntax
  • Format string parameters, e.g. "{}", "{:?}", "{:#?}"
  • Markdown in doc comments

Colophon

All screenshots use xcodedark (which takes advantage of the aforementioned highlight groups) with the SF Mono font in the Medium weight, with iTerm configured to use the Bold weight for bold text (rather than Heavy).

More Repositories

1

vim-colors-xcode

Xcode 11’s dark and light colourschemes for Vim
Vim Script
607
star
2

eldiro

Learn to make your own programming language with Rust
Rust
253
star
3

vim-substrata

A cold, dark colourscheme for Vim
Vim Script
194
star
4

sema

A theme that focuses on what’s important
Rust
103
star
5

vim-corvine

The Raven Dark colourscheme for Vim, rebuilt and modified with Colortemplate
Vim Script
77
star
6

etcetera

An unopinionated Rust library for locating configuration, data and cache directories across platforms
Rust
70
star
7

vim-strand

A barebones Vim plugin manger written in Rust
Rust
47
star
8

eventree

A library for immutable lossless syntax trees in Rust
Rust
28
star
9

vim-swift

A Swift syntax plugin for Vim that aims to match Xcode’s level of detail (WIP)
Vim Script
19
star
10

jsonl

An implementation of JSON Lines for Rust
Rust
16
star
11

vim-plan9

A colourscheme inspired by https://github.com/plan9-for-vimspace/acme-colors
Vim Script
13
star
12

icefall

A cold, clear theme
Rust
12
star
13

intellij-theme

A faithful port of IntelliJ’s themes to VS Code
Rust
11
star
14

lunacookies.github.io

HTML
10
star
15

polytextum

Generate articles and reports from markdown files using pandoc and LaTeX
TeX
8
star
16

rustdoc-theme

A set of VS Code themes that match the themes of rustdoc
Rust
8
star
17

vim-mayanfog

A minimal version of the Mayansmoke colourscheme for Vim
Vim Script
8
star
18

vim-sh

Vim Script
7
star
19

blog

My personal website
HTML
7
star
20

apprentice-vscode

romainl/Apprentice for VS Code!
Rust
6
star
21

sorcisto

A theme based on Apprentice and Sorcerer
Rust
6
star
22

xcode-theme

Xcode’s themes, ported to VS Code
Rust
5
star
23

lang

SCSS
5
star
24

minic

C
4
star
25

fjord

Rust
3
star
26

dotfiles-old

🏡 my dotfiles
Shell
3
star
27

expr-parser

Rust
3
star
28

vim-glance

Vim plugin to search in the current screen
Vim Script
3
star
29

tincture

A Rust library for converting colors between different color spaces
Rust
3
star
30

fictional-dollop

Rust
2
star
31

seoul8

A lifepillar/vim-colortemplate rewrite of junegunn/seoul256.vim with some personal tweaks
Vim Script
2
star
32

syntax-rust

Provides highlighting for Rust code.
Rust
2
star
33

noel

Rust
2
star
34

mottle

Create themes for VS Code with ease
Rust
2
star
35

polyp

An experiment inspired by https://matklad.github.io/2019/11/16/a-better-shell.html
Rust
2
star
36

psychic-telegram

WIP systems programming language that compiles to C
2
star
37

vim-oldbook8

KKPMW/oldbook-vim rebuilt in Colortemplate
Vim Script
2
star
38

gradient

A basic CLI gradient image generator with Oklab and Oklch
Rust
2
star
39

simple-kpc

dumb flaky c library for measuring perf counters easily on macos
C
2
star
40

vim-apparition

Vim Script
1
star
41

haze

random repo name lol
Rust
1
star
42

terminal

Rust
1
star
43

n-times-faster

C
1
star
44

attoutils

A Rust reimplementation of some *nix utils for educational purposes
Rust
1
star
45

didactic-eureka

WIP systems programming language
Rust
1
star
46

vim-tabhelp

Opens vim’s `:help` in a new tab
Vim Script
1
star
47

seoul

A VS Code theme based on seoul256.vim
Rust
1
star
48

slate

A VS Code theme inspired by Spacegray for Sublime Text
Rust
1
star
49

chibicc

yet another language attempt
C
1
star
50

elm-arch-demo

Rust
1
star
51

rschat

A toy chat thing in Rust
Rust
1
star
52

shiny-barnacle

Zig
1
star
53

spectra

Rust
1
star
54

pipes-fast

C
1
star
55

eclipse

VS Code themes based on Eclipse’s defaults
Rust
1
star
56

XPCDemo

Objective-C
1
star
57

FastGaussianBlur

Objective-C
1
star