Vim is old and popular text editor. Vim roots goes to the vi. Vim is improved version of vi. Vim has a lot of features that makes users life better. One of the most loved vim feature is syntax highlighting. Syntax highlighting makes text or code easily readable by coloring statements. For this tutorial we will use following C code. Save this file as my.c .
printf("I love Poftut.com\n");
Open File With Vim
We will open file with vim and insert code above.
$ vim my.c
Press i to switch insert mode and paste code above
and then save the code with Escape : w
Turn On Highlighting
We will use
:syntax on command in the vim in order to turn on or enable syntax highlighting
Turn Off Highlighting
We will give following command to turn off
Make Highlighting Setting Persistent
Highlighting setting can be made persistent by adding setting to the setting files. There is two setting files to configure vim . First one is user setting file which is active for the current user and located in the current user home directory. This setting file is preferred system wide setting file.
$ echo "syntax on" >> .vimrc
Second setting file is system wide and locate at /etc/vim/vimrc . Same setting can be added to this file. This operation requires root privileges
$ sudo echo "syntax on" >> /etc/vim/vimrc