Frequently Asked Question

How do I turn on syntax highlighting in Vim?

Inside a running Vim, type :syntax on and press Enter. The current buffer reformats with colours: keywords in one shade, strings in another, comments dimmed, numbers and operators distinguished. To make the setting permanent, add the same line (without the colon) to your ~/.vimrc. The companion line filetype plugin indent on tells Vim to look at the file extension or content and load the matching syntax definition automatically.

Syntax files live in $VIMRUNTIME/syntax/ (typically /usr/share/vim/vim*/syntax/) and ship for hundreds of languages out of the box: C, Python, Rust, Go, YAML, Markdown, and so on. Each is a Vimscript file that defines regex patterns and maps them to highlighting groups. The actual colours come from a colour scheme try :colorscheme desert or :colorscheme slate to see options, and add colorscheme habamax (or your favourite) to your vimrc. Modern terminals support 256 colours and true colour (set termguicolors), which unlocks the richer palettes used by schemes like gruvbox, tokyonight, and catppuccin.

Neovim has extended this with Tree-sitter: an incremental parser that produces a real syntax tree rather than regex matches. Tree-sitter highlighting is more accurate (it knows whether a token is a function call or a variable), handles edge cases regex cannot, and powers features like structural selection and code folding.

Further reading and video