Sunday, April 10, 2011

Understanding VIM : Beginner's Tutorial-3

In the previous tut.,  we have learned copying/pasting/searching within the file. Now, we are going to take a step further in the direction of Vim editor mastery.
While editing a file, we may need to number the lines with in the file, most probably in case of a program, may be a C program. We can achieve this by this command. (Note that we are in last line mode.)
:set number 
or its abbreviation:
:set nu 
Lines now appear numbered, upon writing the file, the numbers will not be written in the file. It's only for your viewing. Line numbers are displayed either until you quit the vi session  until you disable the set
option: 
:set nonumber 
or
:set nonu 

To temporarily display the line numbers for a set of lines, you can use the # sign. For example:
:1,10# 

Longer words that have been used previously, can be searched using, Ctrl-p or Ctrl-n. Let's say you're typing the word searching, which you've already used once in a document. Type "ear" and then hit Ctrl-p, and Vim will either autocomplete the word if "ear" is a unique string, or show a list of words that begin with "ear". The Ctrl-p command searches for "previously" used terms and displays them in that order, and Ctrl-n searches for the "next" terms, and displays in that order. For most uses, they're pretty equivalent.
We can set abbreviation in Vi editor using ab.
:ab hkm hakkunnamatata 
OR
:ab iot Institute of Technology

So the first argument is the abbreviation, the second argument to the :ab command is the expansion. Now, when you type the characters hkm (in insert mode) you'll get hakkunnamatata. What happens if you want to unset an abbreviation? You could exit Vim, and the abbreviation will go away when the session ends.
But it sounds like fool's way of doing things. There is another sound way.
:una hkm 
To disable all abbreviation -
:unab abbr
To list your currently defined abbreviations, type:
:ab 
  

No comments:

Post a Comment