Sample .vimrc settings

Sample .vimrc settings

Vim, which stands for Vi IMproved, is an open-source, multiplatform text editor extended from vi. It was first released by Bram Moolenaar in 1991. Since then, numerous features have been added to Vim, many of which are helpful in editing program source code. Vim is today one of the two most popular editors for programmers and users of Unix-like operating systems, alongside Emacs. I have used Vim since I started first year in Monash University, and I am using it on my everyday programming while work. I think it is valuable to have some simple and useful .vimrc settings explained and understood before using Vim. The following is the basic setting I have in my .vimrc file. To turn on the syntax highlighting
syntax on
To define the number of stops for tab
set tabstop=4
If you want the tabs to be replaces by spaces, which means when you press “Tab” on the keyboard, Vim will enter the number of spaces you defined in the tabstop setting above
set expandtab
I personally prefer highlight search rather than incremental search. What highlight search does is highlight all words found, so you have a very clear view of the result. Incremental search will search as you type in the keyword, but no words are highlighted after you hit enter. To set highlight search, use
set hlsearch
To set incremental search, use
set incsearch
If you want the line number appear in the editor, use
set number
Use abbreviation you can define a tag for a long sequence of characters. When you type that tag, vim expands the tag to the text it represents, and therefore save your keystrokes. For example, when I’m writing a PHP class, I need to add comments on top of each function and member attribute, I need to type in
/***
 *
 ***/
Of course this long typing is boring. So I want to define an abbreviation such that whenever I type the _comment, it is replaced automatically by that long stuff with PHP comments. That’s what the ab command is for. So I have the following set in my .vimrc file
ab _comment /***
Ctrlv Enter * Ctrlv Enter***/
The key point is, to enter special characters such as newline, first push Ctrlv. Be aware that in newer versions of Windows gvim, Ctrlv is mapped to do paste. In that case, to enter a special key, you need to use Ctrlq instead. Those are basic setting in Vim, I will add more advanced settings in the following articles.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!