Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interactively set syntax highlighting in VI editor

Tags:

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?

like image 520
Toshi Avatar asked Oct 18 '13 07:10

Toshi


People also ask

How do I enable syntax highlighting in vi?

Enabling syntax color schemePress the "i" key to enter insert mode. Hold Shift and hit : then type wq to save and quit the file. You should now be able to use vi and the colorscheme you choose to edit files.

What vim configuration option will activate syntax highlighting?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

How does syntax highlighting work in vim?

Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.


2 Answers

Type following command after a colon:

:set ft=sql. 
like image 83
Karol Król Avatar answered Sep 23 '22 13:09

Karol Król


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.

like image 33
facundofarias Avatar answered Sep 21 '22 13:09

facundofarias