I just discovered a way to use templates in Vim where when I create a file, depending on the extension of the file, the boilerplate text that should always be there will be there.
You can find out how to do this from the Vim Recipe book, in particular this page: http://vim.runpaint.org/typing/using-templates/
Tags: templates
The most attractive feature that VI has to offer is the block visual mode. It is amazingly powerful, especially for those who do coding. With it you can add characters to or remove characters a block of text in a column fashion. For example, you can add characters to a block of text (Figure 1) instantly (Figure 2).

Figure 1

Figure 2
Of course, with power comes complexity. It’s something meant for users whose keyboard (shortcut) dexterity surpasses that of the mouse.
Tags: block, vertical edit, visual
Some of the commands that you use for every session can be placed in a file named “.vimrc” in your home folder.
Personally, when editing code, I like to have my tabs to be of 4 characters wide. I also want the tab characters to be changed to 4 spaces. So in my .vimrc file, I place the following lines:
set smartindent set tabstop=4 set shiftwidth=4 set expandtab
I can then code and have the next line auto-indented. (There is another option called autoindent but it is not as good as smartindent.)
With the options set, the lines can also be indented in command mode or visual mode with the characters >> (shift dot key twice) and un-indented with << (shift comma key twice).
Tags: indentation, vimrc
More on VI…
H – position the cursor at the top of the screen (left most position)
M – position the cursor in the middle of the screen (left most position)
L – position the cursor in the bottom of the screen (left most position)
G – position the cursor at the bottom of the file (left most position); last line in file
gg – position the cursor at the top of the file (left most position); first line in file
:n – position the cursor at line n of the file
Tags: positioning
This is a one of many mini-posts that I will do on using the VI editor. I’ve recently bumped into some pages that contains valuable information on how to use VI. The problem with it is its too wordy and that makes it hard to look for information when you need it.
So this post and the following ones will use tags relevant to the subject to help the search for relevant information quicker.
D – delete the characters of the line after the cursor position
C – delete the characters of the line after the cursor position and change to insert mode
R – change to insert & overwrite mode; it’s like pressing the Ins key on the keyboard; whereas ‘r’ replaces a single character, ‘R’ replaces every character that you type over
s – behaves like ‘x’ but switches to insert mode
S – deletes the whole line and change to insert mode
Tags: delete, substitute, tips
When doing some simple programming, I like to use the Vim editor instead of using a full-blown IDE. It’s a good editor but I want to use it more efficiently. Some of the things I customise for myself are:
These settings are saved in a file named .vimrc in each user’s home directory. Simply save the vi commands in this file to have your customisation. But remember to remove the semicolons. Below is my .vimrc contents to achieve my customisation.
set tabstop=4
set autoindent
colorscheme wombat
wombat is a colour scheme file which I saved in the directory /usr/share/vim/vim71/colors/.
P.S. While searching for some help on setting the file types in Vim, I found this page in wikibooks.org that describes the tips a programmer would use. It’s unbelievably useful. Do check it out if you use vi editor!
Another page with some useful tips is http://tips.webdesign10.com/general/vim
Tags: tips
Further to my previous post on changing the tab size in the VI editor, I’ve found out how to change the indentation size in VI.
The vi editor is a powerful editor. Problem with it is that it is only for the command line which means that many preferences are not accessible via a ‘Preferences’ page. You need to know how to set preferences using commands.
Recently I’ve found out how to change the tab size in the vi editor. I think by default the tab size is 8 characters, which is too long for coding with proper indentation. To change it to a four character stop, use the following command in command mode:
:set tabstop=4
(more…)
Tags: tabstop