Special Offer: Website Builder Plans, 15% Off - Use coupon code 'angwebsites' Malta Web Hosting Home | Contact ANG Malta Contact | ANG Malta Terms and Conditions Terms | ANGMalta.net Sitemap Sitemap   

Brief introduction to the vi Editor

02/08/07

Permalink 08:10:00 am, by ANG Malta Email , 647 words, 2726 views   English (US)
Categories: UNIX and Linux

Brief introduction to the vi Editor

The use of VPS/VDS (Virtual Private Servers or Virtual Dedicated Servers) on the Internet is becoming quite popular, and the large majority of these run Linux distributions.

The normal, day to day administration is done through browser based interfaces, such as Plesk, however, you also can use shell access to administer the server, where you can have total control over the server via a secure SSH connection using a program such as Putty. (available for download free from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

This type of server administration is also very popular, allowing for work to be done remotely across the internet in a safe way.

Putty’s normal use is text based command line administration, although remote graphical interface administration is also possible.

Definitely when you are administering a Linux (or UNIX) server remotely through a command line interface you will need to use a text editor. Linux comes with a wide range of text editors, however, the most popular are vi and emacs. This article gives a very brief introduction to vi.

[More:]

The vi editor was developed in 1976 by Bill Joy at the University of California. An enormous amount of text based and graphical based editors came out from that time, however, the vi is still very popular amongst the Linux / Unix users.

To open vi there are several ways. The simplest is to type ‘vi’ and press enter. This opens vi and creates a new file. The second way of opening vi is to type ‘vi filename’ where filename is the name of the file that you want to edit. This opens vi, and then opens the file you want to edit in it.

When you open vi, you will have a box at the top, representing the cursor. The line in the bottom will give you useful information regarding what operation you are currently doing. Empty lines are marked with a starting ‘~’ character.

There are two operating modes, command and input. When started, vi will be running in command mode. In command mode, vi will consider your input as commands, and when in input mode, vi will consider what you type as text in the file. Always remember that you are working in a case sensitive environment – heLLo is different from Hello.

To start inserting text, you can use the following two commands:

  • ‘a’ – Add command. Text will be inserted to the right of the current cursor position
  • ‘i’ – Insert Command. Text will be inserted starting from the left of the current cursor position.

Pressing the ‘Esc’ key will take you back into the command mode once you are ready inserting/editing the text in the file.

To exit from vi, use the following commands (remember to press the ‘esc’ key first to go back to command mode) :

  • ‘ZQ’ – Exit without saving the changes
  • ‘ZZ’ – Exit and save the changes

To go around in a document, go in insert mode and use the arrow keys. Most versions of vi also support the PgUP and PgDOWN keys to scroll multiple pages.

To delete text, in insert mode use the normal ‘DEL’ and ‘Backspace’ keys. In command mode, you can use the following:

  • ‘x’ – deletes the character under the cursor
  • ‘X’ – deletes the character before the cursor
  • ‘dw’ – deletes from the current character to the end of the current word
  • ‘d$’ - deletes from the current character to the end of the current line

Other useful commands:

  • ‘u’ – Undo previous change
  • Ctrl+R – Redo previously undone change

To search for text:

  • ‘/example’ – Searches forwards from the cursor position for the word ‘example’
  • ‘?example’ – Searches backwards from the cursor position for the word ‘example’

Other resources

http://www.cs.rit.edu/~cslab/vi.html provides a list of commands available for the vi editor.

Trackback address for this post:

http://www.angmalta.net/blog/ang/htsrv/trackback.php/27

Comments, Trackbacks, Pingbacks:

No Comments/Trackbacks/Pingbacks for this post yet...

This post has 2 feedbacks awaiting moderation...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Malta Web Design | Web Hosting | E-Commerce | SEO

Providers of complete web presence solutions, including website design, hosting and development. Fantastic prices on Electronic Commerce and Content Management Systems!

January 2009
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
      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  

Search

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 1

Subscribe via E-Mail

Enter your email address:

Delivered by FeedBurner

Add our feed to your online news reader:

Add to My Yahoo!
Google Reader or Homepage
Subscribe with Bloglines
Subscribe in NewsGator Online
Add to My AOL
Rss fwd
Add to Technorati Favorites!
Add to netvibes

powered by b2evolution free blog software
Web Design Blogs - BlogCatalog Blog Directory
Blog Directory