Vim configuration Tips

Not many of you’d be using Vi, I even try to use it in Win32 System. Without doubt its one of my favourite editors even though if I know only 1% about it.

The vim config file is generally placed in your home directory “~” or “/home/username”

In Win32 system its placed in your “c:\Vim\_vimrc”

Here are the common configurations in my file

set ts=4
” Sets the tab stop to 4 spaces
set sts=4
” Sets the soft tab stop,
“generally used when indenting in Insert mode
set sw=4
” Shift width, no of spaces for auto indentation
set cindent
” Set automatic C type indentation
colorscheme desert
” My favourite colorschem in GUI mode
set nowb
” Prevents automatic write backup
” before overwriting file
set nobk
” Prevents keeping of backup
” after overwriting the file
set showmatch
” Displays or matches the cursor
” after completing a bracket
set bsdir=last
” Last accessed directory is default working directory
set nu
” Sets numbered lines ON
let java_highlight_java_lang_ids=1
” Highlighting of all java.lang.* identifiers

set expandtab
” If you want spaces instead of tabs

The ” is the begining of the comment in the vi configuration file

Vi is capable of handling a lot many file types, It normally picks up the filetype from the extension of the file or the heading content of the file.

You can otherwise force vi to consider a particular file type to be of a particular extension

set filetype=php
set ft=apache
set ft=xml
set ft=sql
set ft=java

Above are some of the types I commonly use.

You can also place all the commands above in a text file, all you need to do is place vim: (commands) : in the text of your document. So if you want a my-server.conf file to be considered as an Apaceh configuration file with 4 spaces for a tab, you can place the following piece of code in the Apache comment

# vim: ts=4 sts=4 sw=4 ft=apache :

You can see the screenshot of my Vim (Win32) editing a XML file.



One Response to “Vim configuration Tips”

  1. ruturajv Says:

    Typically when programming on the dark shell background, the blue comments look aweful cause they are not distincly readable on the black screen for that we can set following command to change comment’s color to light blue.

    highlight Comment ctermfg=lightblue

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: