customize vim editor

Here are a few lines, which might be helpful to you in customizing your very own Vim editor, especially if you are a beginner...
I too am a beginner, so whatever I write here is only what worked for me... if you have better suggestions, do write a comment...

Any command we give in the vim window, is applicable only for that run of vim. The next time you'll login, the default commands will be set.
To make your settings permanent do the following:
open vim from the linux terminal:

vim


Next, type in the following command:

:edit ~/.vimrc


Here we want to edit the .vimrc file, which is supposed to store all the settings.
Now any settings you want to make, just append the file with the command.

1. Tablength : this is something which most of us would like to customize according to self. The command for this is

set tabstop=[no. of spaces]


2. Syntax highlighting : the command for this

syntax [on/off]


3. Automatic indentation :

" Turn off simple indentation (if the current line is indented,
" autoindent will indent the next line by the same amount).
set noautoindent
" Turn off C-style indentation (which adds indentation after lines
" which end with a { character, for example).
set nocindent
" Turn off the two 'formatoptions' ('fo' for short) which
" automatically insert comment characters for the current filetype
" when Vim thinks you want to add a line to a comment.
set fo-=r fo-=o


This isn't enough though, because these values can get overridden by filetype plugins, which set options they think are appropriate for particular types of file. So files which Vim thinks are C, C++ or Java programs get the cindent option turned on when you start editing them.
According to the documentation, you can avoid this as follows:

" Should turn off the automatic indentation options set
" by filetype-specific 'indent' plugins, but doesn't.
filetype indent off


This prevents Vim from loading files like indent/c.vim, which set indentation options for specific languages, but it unfortunately it doesn't have the desired affect (at least for Vim 6.1 on Debian). The indentation script for C has setlocal cindent in it, as you'd expect, but the generic filetype plugin ftplugin/c.vim also sets that, which I think is a mistake. The generic script also sets the options which continue comments across lines, so that solution probably wouldn't be adaquate anyway.
The solution I'm using for now, which does seem to work, is to set certain options after the filetype-specific commands have been run, and doing so for every file type. That can be done with an autocommand for the FileType event:

" This works, and overrides the options for any filetype.
autocmd FileType * set fo-=r fo-=o nocindent noautoindent

4. Line Numbers : To show line numbers, this is the command
set number

I would write more.. when I'm more into using Vim... for now.. enjoy!

SOURCE

Comments

Popular Posts