Skip to content

Instantly share code, notes, and snippets.

@ChrisPenner
Last active December 8, 2021 22:15
Show Gist options
  • Save ChrisPenner/f81959a62d93e39ce7fd to your computer and use it in GitHub Desktop.
Save ChrisPenner/f81959a62d93e39ce7fd to your computer and use it in GitHub Desktop.
Syntax highlighting for text files, breaks up walls of white text.

Plain-text Syntax Highlighting

Over the years I've gotten used to reading code with syntax highlighting. The colouring of the highlighting provides anchoring points for my eyes as I scroll, helping me to keep my place. However, when I'd be editing plain-text, I have no anchoring points, just a huge wall of text; so I wrote a simple syntax file for it.

All it does is highlights capitalized words, very simple. This typically ends up highlighting things of importance: headings, names, and most importantly the beginning of sentences. I've found this to be a good amount of highlighting without being overwhelming, providing context without being overly flashy.

Here's my current version: Plain-text Syntax Highlighting

Other things I've tried:

  • Highlighting words before punctuation (way too much stuff, and highlights the ends of sentences rather than the beginnings)
  • Highlighting the beginnings of lines (Doesn't really provide context anchors, since it's mostly uniform)
  • Highlighting 'even-numbered' lines (ugh... stripes)

Installation

Getting this to work is super easy,

  1. Download the text.vim file and put it in ~/.vim/syntax/text.vim
  2. Make sure you have syntax on in your ~/.vimrc Done!!
" Place this in ~/.vim/syntax/text.vim and Vim will pick it up automagically for text files. (Must have `syntax on`)
" Vim syntax file
" Language: text
" Maintainer: Chris Penner
" Latest Revision: 14 May 2015
if exists("b:current_syntax")
finish
endif
"----------------------------------------------------------------/
" Regex for capitalized words, add your own matches here:
syn match beginSentence '[A-Z][a-z]*'
"----------------------------------------------------------------------------/
" Setup syntax highlighting
"----------------------------------------------------------------------------/
"
let b:current_syntax = "text"
hi def link beginSentence Typedef
" Choose other options to get a different colour:
" Valid options: Comment Constant Function Keyword Operator PreProc Repeat Special Statement Type Typedef
Copy link

ghost commented Mar 13, 2017

exactly what I was looking for. simple and nice. thanks so much

@bzyk69
Copy link

bzyk69 commented Nov 21, 2017

Nice, simple, and easy. And usefull. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment