Vim Syntax Highlighting How To Turn On , Off – POFTUT

Vim Syntax Highlighting How To Turn On , Off


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 .

#include "stdio.h"  

int main(){ 
    if(1==1) 
    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

:syntax on
Turn On Highlighting
Turn On Highlighting
Turn On Highlighting
Turn On Highlighting

Turn Off Highlighting

We will give following command to turn off

:syntax off

Turn Off Highlighting
Turn Off Highlighting

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
Make Highlighting Setting Persistent
Make Highlighting Setting Persistent

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
Make Highlighting Setting Persistent
Make Highlighting Setting Persistent

LEARN MORE  Python String Variable Type

Leave a Comment