If you use Vim for programming, you find that by default based on the type of the file, Vim enables syntax highlighting. That is if your file name is myfile.c or myfile.C, Vim enables Syntax highlighting for the C language. Likewise, it enables syntax highlighting for a large number of well known (programming) languages. If you are wondering where you can find these syntax highlighting files, you can check the following directory.
Currently in my system, it is located in the following directory
Let’s check the directory contents
$ ls /usr/share/vim/vim73/syntax
config.vim idl.vim plp.vim tf.vim
conf.vim indent.vim plsql.vim tidy.vim
context.vim inform.vim pod.vim tilde.vim
cpp.vim initex.vim postscr.vim tli.vim
crm.vim initng.vim po.vim tpp.vim
crontab.vim inittab.vim povini.vim trasys.vim
Thus for every programming language, they have an associated .vim file. For C++, there is cpp.vim. For crontab entries (/etc/cron.d), there is crontab.vim
Since, I am using Vim 7.3, the above syntax files are located in the vim73. But if you are looking for future versions, you can run the following command to get the location
$ find /usr/share/vim/ -iname "*syntax"
ls is used to see the contents of a file. With the option -l, one can see the file/directory permissions for owner,group and others. This option is also useful to see information like the owner and group owner and size of the file.
let’s take a simple example. Seeing the detailed listing of a /usr/local/share/man/man1
$ ls -l /usr/share/man/man1/* | head -20
-rw-r--r-- 1 root root 1010 2008-08-20 19:05 2vcard.1.gz
-rw-r--r-- 1 root root 592 2010-06-25 18:20 411toppm.1.gz
-rw-r--r-- 1 root root 292 2010-07-21 21:45 a2j_control.1.gz
-rw-r--r-- 1 root root 413 2010-07-21 21:45 a2jmidi_bridge.1.gz
-rw-r--r-- 1 root root 424 2010-07-21 21:45 a2jmidid.1.gz
-rw-r--r-- 1 root root 4656 2010-07-12 17:11 a2p.1.gz
-rw-r--r-- 1 root root 5976 2010-08-16 16:25 a2ping.1.gz
-rw-r--r-- 1 root root 1356 2009-04-29 02:17 a2psj.1.gz
-rw-r--r-- 1 root root 798 2010-03-05 07:47 aalib-config.1.gz
-rw-r--r-- 1 root root 2608 2010-11-19 02:50 ab.1.gz
-rw-r--r-- 1 root root 1024 2010-07-02 16:05 ac3dec.1.gz
-rw-r--r-- 1 root root 20 2009-11-07 04:28 ace.1p.gz
-rw-r--r-- 1 root root 11985 2010-01-04 20:33 ack-grep.1p.gz
-rw-r--r-- 1 root root 1136 2010-02-02 06:29 aclocal-1.11.1.gz
-rw-r--r-- 1 root root 1068 2010-06-20 08:14 acl.php.1.gz
-rw-r--r-- 1 root root 1380 2010-10-22 03:46 aconnect.1.gz
-rw-r--r-- 1 root root 738 2005-10-25 15:32 aconnectgui.1.gz
-rw-r--r-- 1 root root 697 2009-12-25 13:56 acpi_available.1.gz
-rw-r--r-- 1 root root 367 2010-06-23 08:06 acpi_fakekey.1.gz
-rw-r--r-- 1 root root 823 2010-05-15 17:39 acyclic.1.gz
Since the above directory is a big directory, we used head to filter out first 20 lines. This example is going to be used in various tutorials like Vim Visual Block.
Vim has various modes like the normal mode, insert mode and visual mode. In the visual mode, you can perform various actions as you can do with other GUI based text editors and mouse. One of the best features of Visual mode in Vim is the ability to select text for performing various actions like copying, deleting and changing the case (upper case to lower case).
- Introduction to Vim Visual Mode
- Vim Visual block
- Example used for explaining the Visual mode
If you don’t want to use the current colorscheme and want to use the default colorscheme of vim, enter vim
$ vim filename
Now in the normal mode, enter
This will set the colorscheme temporarily (for this session, until you exit) to default.
Vim has a number of colorshemes like default, blue, darkblue, desert. A colorscheme describes what color you want to give to the background of your vim editor, the color of the text, and various colors for the different types of programs or text files.
- How to find the available vim colorschemes?
- How to set colorscheme in VIM?
- How to change VIM colorschme permanently?
- How to set default colorscheme in VIM?
- A sample vim colorsheme.
After finding out the available colorscheme of VIM in your machine, the next step is to set a colorscheme.
Let’s assume that you have the following colorschemes available
Now to set the colorscheme to blue
$ vim filename.txt
Enter the following in Normal mode
As you can see the syntax for setting a colorscheme is
Note that if you enter a scheme name which is not available, you will get the following error
E185: Cannot find color scheme abc
You can change a colorscheme using the same command.
Note that when you change a colorscheme by the above method, it is for a particular session only. Once you exit, you will lose the change. Read How to change a VIM colorschme permanently?
You can temporarily change a colorscheme of vim using the following method.
But this change will be transient and as soon as you exit from vim, you will lose the setting. In order to save this setting permanently, you must add this to your .vimrc file
$ vim ~/.vimrc
Add the following lines to the end of the file
Now whenever you open vim, you will see the blue colorscheme. You can use different available vim colorscheme like dessert,darkblue