Highlight lines that are more than 80 characters
When I code, mostly in Ruby but always in vim, I tend to follow the thoughbot styleguide. One rule is Break long lines after 80 characters. Keeping track of the 80 character limit requires me to think about it, which causes me to lose focus.
Sometimes I decide to break the 80 character rule (guide ?) because the line is more descriptive if I make it 85 characters long. (I prefer descriptive methods above length rules, sue me!). This is where my bit of Vim magic comes in. This vim configuration highlights all lines when they cross 80 characters but first warns when you get near the set limit.
The first two lines declare how the highlight should look (LineProximity and LineOverflow). I’ll get to that later. The autocmd make sure when vim opens a buffer (or any of the other options) and it’s a .rb (Ruby) or coffee file it checks the regex and decides if it should highlight a line.
Checks for anything between 80 and 85 and marks it with a gray background. This is Proximity.
Anything after the 84th character will have a red background. This is LineOverflow.
Check out the gif below. Looks nice doesn’t it? Depending on your colorscheme it makes the colors pop more.
You can customize this by changing the file extensions or changing the character length. Next up is making this into its own plugin with some smarter behaviour.
How to use?
Pop the lines in your .vimrc and you’re good to go.
Hope you enjoyed this post :smile: