vi Editor Commands to Remember by Heart

Posted on 12 December 2008

The VI editor is a screen-based editor used by many Unix users. The VI editor has powerful features to aid programmers, but many beginning users avoid using VI because the different features overwhelm them. The best way to learn is to remember these commands by heart, and print out this post and get a free shell account online to practice these and other Linux commands… There’s no better way than to experience things yourself.

Starting the VI Editor

The VI editor lets a user create new files or edit existing files. The command to start the VI editor is vi, followed by the filename. For example to edit a file called temporary, you would type

vi temporary

and then return. You can start VI without a filename, but when you want to save your work, you will have to tell VI which filename to save it into later.

When you start VI for the first time, you will see a screen filled with tildes (A tilde looks like this: ~) on the left side of the screen. Any blank lines beyond the end of the file are shown this way. At the bottom of your screen, the filename should be shown, if you specified an existing file, and the size of the file will be shown as well, like this:

"filename" 21 lines, 385 characters

If the file you specified does not exist, then it will tell you that it is a new file, like this:

"newfile" [New file]

If you started VI without a filename, the bottom line of the screen will just be blank when VI starts. If the screen does not show you these expected results, your terminal type may be set wrong. Just type :q and return to get out of VI, and fix your terminal type. If you don’t know how, get some help.

Why are we hiding from the police daddy? - Because we use vi son, they use emacs


Getting Out of VI

Now that you know how to get into VI, it would be a good idea to know how to get out of it. The VI editor has two modes and in order to get out of VI, you have to be in command mode. Hit the key labelled “Escape” or “Esc” (If your terminal does not have such a key, then try ^[, or control-[.) to get into command mode. If you were already in the command mode when you hit “Escape“, don’t worry. It might beep, but you will still be in the command mode.

The command to quit out of VI is :q. Once in command mode, type colon, and ‘q’, followed by return. If your file has been modified in any way, the editor will warn you of this, and not let you quit. To ignore this message, the command to quit out of VI without saving is :q!. This lets you exit VI without saving any of the changes.

Of course, normally in an editor, you would want to save the changes you have made. The command to save the contents of the editor is :w. You can combine the above command with the quit command, or :wq. You can specify a different file name to save to by specifying the name after the :w. For example, if you wanted to save the file you were working as another filename called filename2, you would type: w filename2 and return.

Another way to save your changes and exit out of VI is the ZZ command. When in command mode, type ZZ and it will do the equivalent of :wq. If any changes were made to the file, it will be saved. This is the easiest way to leave the editor, with only two keystrokes.

Not what you are looking for? Try Google Search!





People who liked this Post also read

This post was written by:

R. MAK. - who has written 233 posts on ixibo.

How Should I describe me?... Well! I am a simple dude, who likes to indulge in intelligent conversation with an intelligent people, specially on technology topics hope you are one of them :p

Popular Tags

 practice vi editor online , vi exit recording , vi editor commands , android vi editor , vi android commands , android vi editor save , android vi save , hot to go out vi editor , vi recording exit , vi editor android , exit vi android , vim exit recording , stop recording in vi , refencnce for vi editors , vi editor android installation , recording vi editor , vi editor commands in linux , vi editor commands printout , recording vi , vi editor cydia , vi editor exit record , vi editor how to quit recording , vi editor if fi commands , unix vi c5b , vi edit mode android , stop vi recording , top 10 vi commands , vi android editor , tips to remember vi commands , vi comands printout , vi commands android , text editor vi commands recording , vi dd: not an editor command , terminal for android get out of edit mode , vi edit command android , vi edit message recording , vi copy Not an editor command , vi editor in recording mode , vi editor mac commands a out , vi recording stop , vi recording wq , vi stop recording , vi stop recording linuz , vi Y not an editor command , vim editor recording , ^q ^v android vi , vim exit recording mode , vim recording exit , web based vi editor practice , what is recording in vi editor 

2 Responses to “vi Editor Commands to Remember by Heart”

  1. snarfy says:

    Missing many of the most inportant basic commands, such as:

    “y – “yank” (copy) text into the indicated register

    example: dd”ay – cut current line and copy into register a

    v – enters visual selection mode
    Control-v – enters block visual selection mode

    q – begin recording into selected register

    q – stop recording

    gg – go to top of buffer

    G – go to bottom of buffer

    G – go to indicated line number

    / – begin search

    . – repeat previous action

    @ – seek word under cursor

  2. kosir says:

    Thanks for this! Most of the shell accounts I found here does not have any other text editor installed or I just don’t know about it.


Calendar

December 2008
M T W T F S S
« Nov   Jan »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31