How to interactively set syntax highlighting in VI editor

31.1k Views Asked by At

Using vi, I want to display files in distinguished colors in unix. If I save a file as .sql or .java it will highlight the keywords. I want to make changes to which words are highlighted, and in what color.

How do I control syntax highlighting and color schemes with various vi file extensions?

4

There are 4 best solutions below

0
On

For file specific settings, there is also the power of modelines.

You can put them in the first or last five (unless you change modelines variable) lines to control variable settings.

eg:

# vim: syn=sh

or even:

/* vim: tw=60 ts=2: */

see vim's help: :h modeline

1
On

Are you sure one of the user don't have an alias to vim or something like that? CF: http://masstransmit.com/garage_blog/alias-vi-vim/

0
On

I just did it by putting :syntax on. I suppose you want to save the settings so it can be highlighted each time you open one of those files, in which case the answer by Eric it's the correct one.

0
On

Type following command after a colon:

:set ft=sql.