Dysfunctional Programming

Syntaxless Vim

Posted by roryrjb - Sat 08 Jun 2019 07:59:32 BST

My main editor, for well over a year now has been Vim. For a number of years before that I tried to use it full time but for one reason or another it didn’t fully stick. Now I am more productive and faster in Vim than anything else[0].

There are numerous blog posts and articles all over the web already talking about how to use Vim and how people configure Vim, so I won’t repeat all the good stuff that’s already out there. I want to write about a very small functional aspect of Vim specifically, but more generally what is probably a much bigger deal to a lot of technical text editor users; syntax highlighting. I don’t use it.

Basically it boils down to the fact that I highly value code clarity. I strive to write as good as code as possible of course, but I focus on how readable it is. This is for all the obvious reasons; and not just for the benefit of others but for the benefit of my future self. I guess this all goes without saying really but there’s a lot of code out there that could have been written in a clearer style. Aside from the actual style of code, it also means using clearer algorithms or patterns when the language you are using gives you the choice. If that means the code is actually slower than so be it, but of course there has got to be limits, as always everything is a trade off. Beyond this I think it also affects my choices on actual languages and tools[1].

Without syntax highlighting, it forces you even more to properly read the code. If that code’s style is messy, you will struggle, so it forces you to write clearer code. Without highlighting, Vim is faster because it has less to do. This is most noticeable on very large files. When you open a filetype that doesn’t have a syntax highlighting definition, well it doesn’t matter, so you don’t have to hunt down some plugin that someone has written for it (or write one yourself), your Vim setup is leaner and simpler[2].

To be clear, I still have a colourful and pretty Vim interface (using base16 and vim-airline) it’s only the syntax that is disabled.

If you want to get rid of all colour, you can tell Vim your terminal doesn’t support it:

:set t_Co=0

and disabling syntax highlighting is a simple as:

:syntax off

Vim with base16 colours and airline

I think anyone reading this should try disabling syntax highlighting. It does take a little while to adjust but when you do, as I have done, you no longer even think about it.

One of the reasons for this post is to say that this was clearly seen as a viable use case in Vim (potentially tied to the fact that it can run out of a terminal, I don’t know), but in all other text editors where I have tried to do this there wasn’t an option and it took some work or a workaround. The last time I checked (2018 or earlier) for Atom, Visual Studio Code and Sublime Text you had to either have a syntax highlighting definition where all colours are set the same or force the filetype to be plain text. Which is a shame, I think it is so worthwhile to try this, and for me personally works really well.

[0] For me Vim plugins for other editors just don’t cut it as there’s still a lot of functionality that can’t be accessed via the keyboard and I can’t stress enough just how powerful, flexible and convenient it is to run a complete text editor in a terminal emulator.

[1] As an example, Perl has been called a write-only language but I think context sensitive variables such as $_ actually make the code clearer and more readable. Of course someone unfamiliar with this feature might find that completely incomprehensible but the same could be said about certain language features in all other languages if you don’t know beforehand.

[2] It also means that for some files, for example .vue files which can contain multiple languages, Vim won’t partially highlight the file, everything is just more consistent.

Last updated: Sat 08 Jun 2019 07:59:37 BST