Linux Help

Simple Guide To VI / VIM   
Printable Version

Luke's Vim Guide
Created on December 18th, 2000.

About Vim

Vim is a powerful text editor, which is used by loads of programmers and  others out in nix world. Vim is a clone of Vi (one of the standard text  editors on UNIX systems), which was created by Bill Joy. If you have ever tried vim, you may have asked yourself "This is complicated, wheres pico?",  Dont do this! Vim is not complicated, and when you have the learnt the basic  key strokes, you will be appreciating the advantage of such a powerful editor. 
Its all down to personal choice, thats why you have many Linux Distributions,  and X Window Managers; its the same with editors. There are editors such  as Joe, and Pico which is aimed to please the newbie, or the lazy Sys admin,  who does not need the functions that powerful editors offer. The most popular  editors aimed at the programmers, are Vim and Emacs, and if you march in  to a linux channel (ie, and ask "Which is better, Vim or Emacs?",  then you have created world war III. Emacs is an excellent editor, but  I just prefer Vim. Try both, and see which one you like.

Installing Vim
(you may have it installed, but download the latest anyway  ;))

Goto, and dowload vim-5.7-src.tar.gz and vim-5.7-rt.tar.gz, which are the source and run time files needed for complete installation. Follow the instructions below:

cp vim-5.7-src.tar.gz /tmp
cp vim-5.7-rt.tar.gz /tmp
cd /tmp
tar zxvf vim-5.7-src.tar.gz
tar zxvf vim-5.7-rt.tar.gz

cd vim-5.7/
make install
(as root)

Running Vim

When installation is complete, you are now ready to play around with vim. So lets start by opening vim, which a new file.

vim newfile

Now, you can type away, and your text will not appear on the screen as you would expect. There are different operating modes that vim has to offer, the mode you are in now is command mode. The command mode is the most useful mode to use to mess with your file, ie save, exit, search etc. To be able to type, and edit files like you would do normally, pressing i or the insert button, and this will place you into insert mode. To get back to the command mode, press <Esc>.
So you have loaded vim, with the file you want to create, and you have entered    insert mode, typed to your hearts consent, and now you want to save. Enter    Esc mode, and type ':' this will create a prompt at the bottom, to save,    you type w after the: . To save and exit, you would enter command mode,    and type:wq. You guessed it, to exit without saving, you just type    :q. To force a quit, do a :q!

I have listed all the vim commands that you will find useful:

VIM Commands

Key:                Action:

<Esc>                   Enter command mode
i                             Enter insert mode
R                            Enter overwrite mode
a                             Enter append mode
:w                           Save File
:q                            Exit vim without saving
x                            Delete the character under the cursor
dw                         Delete the current word
dd                          Delete the current line
d$                          Delete everything Right of the cursor
yy                          Yank the current line onto the clipboard
yw                         Yank the current word onto the clipboard
p                             Paste the clipboard
u                             Undo
^r                            Redo
G                             Jump to bottom of file
/text                         Search for the textfrom the cursor

Programming Essential.

All programmers love the use of colors and identation. Heres how you do it:

vim ~/.vimrc

Press i to enter Insert mode, then add these lines to the file

set autoindent
syn on
set cindent

Press <Esc>, enter:wq

now test it, try using vim with the extension of the language you are using (ie perl, html, c) and start typing  a bit of code, and watch the preety colors and indentation.

vimtutor is a good way to learn vim too.

Having trouble? Got questions? Require further assistance? If so please feel free to visit our Help Forums and ask the experts!

Copyright © 1997 - 2017 Private World Domination Inc. All rights reserved.
Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
| Contact Us | Link to Us | RSS Feed | Staff |

DNS Hosting by easyDNS