Backend / DevOps / Architect
Brit by birth,
located worldwide

All content © Alex Shepherd 2008-2024
unless otherwise noted

Syntax highlighting with less.

Published
1 min read
image
Image Credit: Justin Smith

Hey there again people,

I'm always using `cat` to check lines of code within scripts, and find it incredibly frustrating that it has no syntax highlighting functionality. Vim, however, has amazing highlighting. I have found a vim macro which basically causes it to act pretty much identically to `less`. Here's how to use it...

vim -u /usr/share/vim/{vim version}/macros/less.vim {filename}

This, on it's own is a monstrous command, and a bit of a nightmare to type, but if you put this as an alias to vless in /etc/profile, or ~/.bash_profile, then all you'll have to type is vless when you want to access it! It's by no means perfect, but it makes searching through pages and pages of code a lot easier.

There ya go! Two posts in one day! Productive!

See ya!

n00b