PDA

View Full Version : Linux Quick Vi Tutorial



LSA
02-28-2004, 06:27 PM
In this guide I will show some the basics of the text editor 'VI'.

To start VI open up a terminal and type vi

You should see something like this:



                                 VIM - Vi IMproved
~
~                                  version 6.1.320
~                             by Bram Moolenaar et al.
~                    Vim is open source and freely distributable
~
~                           Help poor children in Uganda!
~                  type  :help iccf<Enter>       for information
~
~                  type  :q<Enter>               to exit
~                  type  :help<Enter>  or  <F1>  for on-line help
~                  type  :help version6<Enter>   for version info



That is what I see when I start VI, you may get something different. As you can see I have VIM, one of many VI clones.

To start editing a text file in VI just press 'i' at the first screen, it will take you to insert mode. In insert mode you can do basic text editing like any other text editor.

To save a file press 'esc' (when you press esc you are taken to command mode) then type in ':w [path and filename]'

To exit VI press 'esc' and type in :q, you can also combine this with save like this :wq. If it says your file hasn't been saved then put a ! before q like this ':q!" The ! overrides error messages.

To open a file you can either start the file with vi like this:

vi /path/paaathh/openme

or go into command mode (press esc) and type :e /path/pathhh/file

If you get a message saying that your current file hasnt been saved you will have to save it or override the message.

That is the basics you will need to edit a file in VI, but VI is much more powerful then this and if you want to be an effective linux user you should learn more about it.

I have just started learning about VI so if I got anything wrong tell me please.
Hope this helps someone.

leftism
02-28-2004, 11:53 PM
Ill just add a few more things if I may :)

When in command mode:

x - deletes the character under the cursor
dd - deletes the whole line the cursor is on
dw - deletes the word the cursor is on

yy - copies the line the cursor is on into a buffer
pp - pastes the line in the buffer (this could be a single 'p', I cant remember :lol:)