Vi Quick Reference


Vi has two modes: insertion mode, and command mode. The editor begins in command mode, where cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key.


exit, saving changes : x

quit (unless changes) :q

quit (force, even if unsaved) :q!

Inserting text

insert before cursor, before line i , I

append after cursor, after line a , A

open new line after, line before o , O

replace one char, many chars r , R


left, down, up, right h , j , k , l

next word, blank delimited word w , W

beginning of word, of blank delimited word b , B

end of word, of blank delimited word e , E

sentence back, forward ( , )

paragraph back, forward { , }

beginning, end of line 0 , $

beginning, end of file 1G , G

line n n G or :n

forward, back to char c fc , Fc

forward, back to before char c tc , Tc

top, middle, bottom of screen H , M , L

Deleting text

Almost all deletion commands are performed by typing d followed by a motion. For example dw deletes a word. A few other deletions are:

character to right, left x , X

to end of line D

line dd

line :d

Yanking text

Like deletion, almost all yank commands are performed by typing y followed by a motion. For example y$ yanks to the end of line. Two other yank commands are:

line yy

line :y

Changing text

The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For example cw changes a word. A few other change commands are:

to end of line C

line cc

Putting text

put after position or after line p

put before position or before line P


Named registers may be specified before any deletion, change, yank, or put command. The general prefix has the form “c where c may be any lower case letter. For example, “adw deletes a word into register a. It may thereafter be put back into the text with an appropriate put command, for example “ap.


Named markers may be set on any line of a file. Any lower case letter may be a marker name. Markers may also be used as the limits for ranges.

set marker c on this line mc

goto marker c ‘c

goto marker c first non-blank ‘c

Search for strings

search forward /string

search backward ?string

repeat search in same, reverse direction n , N


The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).

replace pattern with string :s/pattern /string /flags

flags: all on each line, confirm each g , c

repeat last :s command &

Regular expressions

any single character except newline . (dot)

zero or more repeats *

any character in set […]

any character not in set [^ …]

beginning, end of line ^ , $

beginning, end of word \< , \>

grouping \(. . . \)

contents of n th grouping \n


Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example

5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurance of the letter e. Even insertions may be repeated conveniently with this method, say to insert the same line 100 times.


Ranges may precede most “colon” commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.

lines n-m :n ,m

current line :.

last line :$

marker c :’c

all lines :%

all matching lines :g/pattern /


write file (current file if no name given) :w file

append file (current file if no name given) :w >>file

read file after line :r file

read program output :r !program

next file :n

previous file :prev

edit new file :e file

replace line with program output :.!program


toggle upper/lower case ~

join lines J

repeat last text-changing command .

undo last change, all changes on line u , U


Ten Commandments for Peace of Mind

1. Do Not Interfere In Others’ Business Unless Asked.

Most of us create our own problems by interfering too often in others’ affairs. We do so because somehow we have convinced ourselves that our way is the best way, our logic is the perfect logic and those who do not conform to our thinking must be criticized and steered to the right direction, our direction. This thinking denies the existence of individuality and consequently the existence of God. God has created each one of us in a unique way. No two human beings can think or act in exactly the same way. All men or women act the way they do because God within them prompts them that way. There is God to look after everything. Why are you bothered? Mind your own business and you will keep Your peace.

2. Forgive And Forget.

This is the most powerful aid to peace of mind. We often develop ill feelings inside our heart for the person who insults us or harms us. We nurture grievances. This in turn results in loss of sleep, development of stomach ulcers, and high blood pressure. This insult or injury was done once, but nourishing of grievance goes on forever by constantly remembering it. Get over this bad habit. Believe in the justice of God and the doctrine of Karma. Let Him judge the act of the one who insulted you. Life is too short to waste in such trifles. Forgive, Forget, and march on. Love flourishes in giving and forgiving.

3. Do Not Crave For Recognition.

This world is full of selfish people. They seldom praise anybody without selfish motives. They may praise you today because you are in power, but no sooner than you are powerless; they will forget your achievement and will start finding faults in you. Why do you wish to kill yourself in striving for their recognition? Their recognition is not worth the aggravation. Do your duties ethically and sincerely and leave the rest to God.

4. Do Not Be Jealous.

We all have experienced how jealousy can disturb our peace of mind. You know that you work harder than your colleagues in the office, but sometimes they get promotions; you do not. You started a business several years ago, but you are not as successful as your neighbor whose business is only one year old. There are several examples like these in everyday life. Should you be jealous? No. Remember everybody’s life is shaped by his or her previous Karma, which has now become his destiny. If you are destined to be rich, nothing in the world can stop you. If you are not so destined, no one can help you either. Nothing will be gained by blaming others for your misfortune. Jealousy will not get you anywhere; it will only take away your peace of mind.

5. Change Yourself According To The Environment.

If you try to change the environment single-handedly,the chances are you will fail. Instead, change yourself to suit your environment. As you do this, even the environment, which has been unfriendly to you, will mysteriously change and seem congenial and harmonious.

6. Endure What Cannot Be Cured.

This is the best way to turn a disadvantage into an advantage. Every day we face numerous inconveniences, ailments, irritations, and accidents that are beyond our control. If we cannot control them or change them, we must learn to put up with these things. We must learn to endure them cheerfully thinking, “God wills it so, so be it.” God’s plan is beyond our comprehension. Believe in it and you will gain in terms of patience, inner strength and will power.

7. Do Not Bite Off More Than You Can Chew.

This maxim needs to be remembered constantly. We often tend to take more responsibilities than we are capable of carrying out. This is done to satisfy our ego. Know your limitations. Why take on additional loads that may create more worries? You cannot gain peace of mind by expanding your external activities. Reduce your material engagements and spend time in prayer, introspection and meditation. This will reduce those thoughts in your mind that make you restless. Uncluttered mind will produce greater peace of mind.

8. Meditate Regularly.

Meditation calms the mind and gets rid of disturbing thoughts. This is the highest state of peace of mind. Try and experience it yourself. If you meditate earnestly for half an hour everyday, your mind will tend to become peaceful during the remaining twenty-three and half-hours. Your mind will not be easily disturbed as it was before. You would benefit by gradually increasing the period of daily mediation. You may think that this will interfere with your daily work. On the contrary, this will increase your efficiency and you will be able to produce better results in less time.

9. Never Leave The Mind Vacant.

An empty mind is the devil’s workshop. All evil actions start in the vacant mind. Keep your mind occupied in something positive, something worthwhile. Actively follow a hobby. Do something that holds your interest. You must decide what you value more: money or peace of mind. Your hobby, like social work or temple work, may not always earn you more money, but you will have a sense of fulfillment and achievement. Even when you are resting physically, occupy yourself in healthy reading or mental chanting of God’s name.

10. Do Not Procrastinate And Never Regret.

Do not waste time in protracted wondering “Should I or shouldn’t I?” Days, weeks, months, and years may be wasted in that futile mental debating. You can never plan enough because you can never anticipate all future happenings. Always remember, God has His own plan, too for you. Value your time and do the things that need to be done. It does not matter if you fail the first time. You can learn from your mistakes and succeed the next time. Sitting back and worrying will lead to nothing. Learn from your mistakes, but do not brood over the past. DO NOT REGRET. Whatever happened was destined to happen only that way. Take it as the Will of God. You do not have the power to alter the course of God’s Will. Why cry over spilt milk?


Sometimes we just need to be reminded!

A well-known speaker started off his seminar by holding up a $20.00 bill. In the room of 200, he asked,
“Who would like this $20 bill?”

Hands started going up.

He said, “I am going to give this $20 to one of you but first, let me do this.
He proceeded to crumple up the $20 dollar bill.
He then asked, “Who still wants it?”

Still the hands were up in the air.

Well, he replied, “What if I do this?” And he dropped it on the ground and started to grind it into the floor with his shoe.

He picked it up, now crumpled and dirty.

“Now, who still wants it?”

Still the hands went into the air.

“My friends, we have all learned a very valuable lesson.

No matter what I did to the money, you still wanted it because it did not decrease in value. It was still worth $20.

Many times in our lives, we are dropped, crumpled, and ground into the dirt by the decisions we make and
the circumstances that come our way.
We feel as though we are worthless. But no matter what has happened or what will happen, you will never lose your value.

Dirty or clean, crumpled or finely creased, you are still priceless to those who DO LOVE you. The worth of our
lives comes not in what we do or who we know, but by WHO WE ARE and WHOSE WE ARE.

You are special Don’t EVER forget it.”
Pass this on, you may never know the lives it touches, the hurting hearts it speaks to, or the hope that it
can bring.

Count your blessings, not your problems.
“And remember:
amateurs built the ark ..
professionals built the Titanic.”

If God brings you to it – He will bring you through it.


A little boy went into a chemist store, reached for a soda carton and pulled it over to the telephone. He climbed onto the carton so that he could reach the buttons on the phone and proceeded to punch in seven digits.
The store owner listened to the following conversation.
The boy asked, “Lady, Can you give me the job of cutting your lawn?”
The woman replied, “I already have someone to cut my lawn.”
“Lady, I will cut your lawn for half the price of the person who cuts your lawn now.”
The woman responded that she was very satisfied with the person who was presently cutting her lawn.
The little boy found more perseverance and offered, “Lady, I’ll even sweep your curb and your sidewalk, so on Sunday you will have the prettiest lawn in all of North Palm Beach, Florida.”
Again the woman answered in the negative. With a smile on his face, the little boy replaced the receiver.
The chemist, who was listening to all this, walked over to the boy and said, “Son… I like your attitude; I like that positive spirit and would like to offer you a job.” The little boy replied, “No thanks: I was just checking on the job I already have!!!”

Chanakya’s Quotes …… Worth Reading

“Person should not be too honest.
Straight trees are cut first and Honest people are victimised first.”


“Even if a snake is not poisonous,
it should pretend to be venomous.”


“The biggest guru-mantra is: Never share your secrets with anybody. ! It will destroy you.”


“There is some self-interest behind every friendship.
There is no Friendship without self-interests. This is a bitter truth.”


“Before you start some work, always ask yourself three questions – Why am I doing it, What the results might be and Will I be successful. Only when you think deeply and find satisfactory answers to these questions, go ahead.”


“As soon as the fear approaches near, attack and destroy it.”


“Once you start working on something, don’t be afraid of failure and don’t abandon it. People who work sincerely are the happiest.”


“The fragrance of flowers spreads only in the direction of the wind.
But the goodness of a person spreads in all direction.”


“A man is great by deeds, not by birth.”


“Treat your kid like a darling for the first five years.
For the next five years, scold them.
By the time they turn sixteen, treat them like a friend.
Your grown up children are your best friends.”


“Books are as useful to a stupid person as a mirror is useful to a blind person.”


“Education is the best friend.
An educated person is respected everywhere.
Education beats the beauty and the youth.”

Chanakya quotes (Indian politician, strategist and writer, 350 BC-275BC)

« Older entries Newer entries »