# Vim now highlights types, feedback welcome

**URL:** <https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198>\
**Category:** Ecosystem\
**Tags:** vim\
**Created:** [July 18, 2022, 3:23pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198 "2022-07-18T15:23:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maelan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/maelan/32/1184_2.png) [@Maelan](https://discuss.ocaml.org/u/Maelan)\
**Post date:** [July 18, 2022, 3:23pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/1 "2022-07-18T15:23:57Z")

</div>

[A patch](https://github.com/ocaml/vim-ocaml/pull/76) just made its way to [the community-maintained Vim files for OCaml](https://github.com/ocaml/vim-ocaml) (not propagated to the [official Vim distribution](https://github.com/vim/vim/tree/master/runtime), yet), that tries to highlight types. IMHO the patch is large and hacky so you may want to try it cautiously, and _feedback would be appreciated_. 🙂

The former behavior was to highlight identifiers that happened to be the name of a builtin type (such as `int` or `list`), regardless of where they appeared. Now, in principle, all type expressions can be highlighted, and be so only when in a type context. By default, only builtin types are highlighted, but you can unleash the full power of the new linter:

```nohighlight
" put this in ~/.vim/after/syntax/ocaml.vim for instance:
hi link ocamlTypeConstr Type
hi link ocamlTypeBuiltin Type
hi link ocamlTypeVar Type
hi link ocamlTypeAnyVar Type

```

or fancier (if you like excess 🌈):

```nohighlight
" 112 = light green (the color of the “Type“ hl group with my theme)
hi ocamlTypeConstr ctermfg=112
hi ocamlTypeBuiltin ctermfg=112 cterm=bold
hi ocamlTypeVar ctermfg=112 cterm=italic
hi ocamlTypeAnyVar ctermfg=112 cterm=bold

```

Even if you don’t care about highlighting types, allowing the linter to discriminate between types and expressions has some tangential benefits.

---

<div class="post-metadata">

**Author:** ![Juloo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/juloo/32/881_2.png) [@Juloo](https://discuss.ocaml.org/u/Juloo)\
**Post date:** [July 19, 2022, 3:20pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/2 "2022-07-19T15:20:52Z")

</div>

Thanks a lot !

One thing I particularly like is highlighting type variables differently:

```nohighlight
hi link ocamlTypeVar Identifier
hi link ocamlTypeAnyVar Special

```

These tiny `'a`s and `'b`s are sometimes hard to see in the middle of a long type expression.

---

<div class="post-metadata">

**Author:** ![XVilka](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvilka/32/5334_2.png) [@XVilka](https://discuss.ocaml.org/u/XVilka)\
**Post date:** [July 20, 2022, 5:07pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/3 "2022-07-20T17:07:39Z")

</div>

Using [tree-sitter](https://tree-sitter.github.io/tree-sitter/)-based [NeoVim](https://neovim.io/) parser would be probably more promising:

- [GitHub - nvim-treesitter/nvim-treesitter: Nvim Treesitter configurations and abstraction layer](https://github.com/nvim-treesitter/nvim-treesitter)
- [GitHub - tree-sitter/tree-sitter-ocaml: OCaml grammar for tree-sitter](https://github.com/tree-sitter/tree-sitter-ocaml)

This is what I use myself since the NeoVim 0.7.0 release.

---

<div class="post-metadata">

**Author:** ![Maelan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/maelan/32/1184_2.png) [@Maelan](https://discuss.ocaml.org/u/Maelan)\
**Post date:** [July 21, 2022, 11:51am UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/4 "2022-07-21T11:51:13Z")

</div>

Certainly! Unfortunately, Tree-Sitter for NeoVim was merely a thing at the time this hack was written (3 years ago). Worse, it wasn’t available for old Vim, and (I haven’t followed the news but) I don’t think this has changed (I’d be curious if you have pointers; I found [this discussion](https://groups.google.com/g/vim_dev/c/3YX9Xbx2DxU) from last year, in which alternatives are considered but there no conclusion is drawn).

Sadly, old Vim is likely to stay around (and it is apparently taking great delight in diverging from NeoVim more and more… grmbl).

---

<div class="post-metadata">

**Author:** ![XVilka](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvilka/32/5334_2.png) [@XVilka](https://discuss.ocaml.org/u/XVilka)\
**Post date:** [July 21, 2022, 1:00pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/5 "2022-07-21T13:00:40Z")

</div>

Yes, Vim has no plans to adopt Tree-Sitter, at least not in the near future. And yes, with Vim9 substituting old VimL in old Vim and Lua in NeoVim they will divert quite significantly. I am afraid the era of universal plugins that would work in both is gone.

---

<div class="post-metadata">

**Author:** ![beajeanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/beajeanm/32/189_2.png) [@beajeanm](https://discuss.ocaml.org/u/beajeanm)\
**Post date:** [July 21, 2022, 1:11pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/6 "2022-07-21T13:11:39Z")

</div>

The neovim community re-implemented a lot of the best plugin in Lua and added more modern features to the point where I do not see universal plugins as a desirable goal in my set-up.

I think it’s a shame Vim didn’t try to bridge the gap and bring the Neovim community into the fold but re-invented a new imcompatible language instead…

@Maelan a bit off topic, but how do you manage mli in your Vim set-up? I always have some trouble with (Neo)Vim trying to treat them as ml files and I somebody (I think you?) posted about it somewhere but I can’t find the details.

---

<div class="post-metadata">

**Author:** ![Maelan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/maelan/32/1184_2.png) [@Maelan](https://discuss.ocaml.org/u/Maelan)\
**Post date:** [July 21, 2022, 1:55pm UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/7 "2022-07-21T13:55:51Z")

</div>

> [@beajeanm](#):
>
> @Maelan a bit off topic, but how do you manage mli in your Vim set-up? I always have some trouble with (Neo)Vim trying to treat them as ml files and I somebody (I think you?) posted about it somewhere but I can’t find the details.

That was not me, but there is [an open issue on GitHub](https://github.com/ocaml/vim-ocaml/pull/61) (by @undu). I don’t remember encountering problems with ML vs MLI (the linter encompasses both, and Merlin can tell the difference), but it seems it is causing trouble to people with NeoVim and Tree-Sitter.

---

<div class="post-metadata">

**Author:** ![rbjorklin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rbjorklin/32/1126_2.png) [@rbjorklin](https://discuss.ocaml.org/u/rbjorklin)\
**Post date:** [July 23, 2022, 5:34am UTC](https://discuss.ocaml.org/t/vim-now-highlights-types-feedback-welcome/10198/8 "2022-07-23T05:34:01Z")

</div>

Just want to say thanks for sharing/mentioning this. I had somehow completely missed Treesitter and been unhappy with the syntax highlighting in vim/neovim, this is quite the improvement!
