Swimminginthought

A place for all things technical and my mind..

Menu
  • About Me / Hire Me
Menu

A simple overview of how to use one of the most powerful text editors; vi

Posted on March 25, 2012 by Percy Kwong

Vi is a text editor that is included by default in every linux, unix, and *bsd installation.  Every person who’s serious about using this should learn the basics of it.  Very powerful, but a bit hard to learn, it’s something that everybody who manages a linux, unix, *bsd box should learn to use at least on a basic level.

There will be times (I promise you) where you will need to use it and not have the facilities to download and install the editor you normally use.

To launch vi and create a new file, simply go to your location where you want to create the file and simply type:

vi filename

if you want to modify a file, do the same, just cd to the location where the file is and just type vi filename.you.want.to.modify

Getting around.. Moving the cursor.

Arrow Keys… NOT!   vi does not use arrow keys, but to move the cursor around, you would use the following four keys:   H,J,K,L   (respectively, left, down, up, right).

Now like every other editor, you would move the cursor to where you want it to be (make your edits) and do one of the following:

type: i to insert from the following location.  When done inserting text, just hit the ‘esc’ (escape key)

type: o to open a new line below where the cursor is so you can enter a new line.

type: x to delete the current character.

type: /search term      to find instances of your search term.  You can just hit ‘/’ to find the next instance.

type: dd to delete the current line.

These are the basics of moving around and doing stuff in vi.  Now for some useful tidbits that believe me you’re gonna be glad you know.

Type: ‘esc’ then ‘:q!’ to quit without saving because you messed up.

Type ‘esc’ then ‘:wq!’ to write your changes and quit, because you’re done making changes.

Type’esc’ then ‘: w <filename>’ to write your changes to a different file.

The one super-power I give vi.  Search and Replace Globally.

Let’s say you want to replace every instance of the word, “tomato” with the word “carrots” in the file.  Something you’ll eventually want or need to do.

Type ‘esc’ then ‘:%s/tomato/carrots/g’

The slash g means global. I’m pretty sure you get the idea.  There are so many other things vi can do, but it would literally be a small novella.  I exclusively use vi for all my editing tasks.  Why?  It’s always there and it’s consistent and reliable.

Hope this helps!

 

4 thoughts on “A simple overview of how to use one of the most powerful text editors; vi”

  1. Percy Kwong says:
    March 28, 2012 at 8:55 am

    A better option for learning vi is to just type “vimtutor” and follow along.

    Reply
    1. admin says:
      March 28, 2012 at 9:00 am

      This assumes that vim in installed which is in a lot of ways different from vi. The purpose of this post is to educate someone on the very basics of editing a file in the event of a disaster. The concept is to prepare a customer for that one incident where a simple change can bring up the box. Vi is always installed and vim not necessarily. Although, it’s a great tip on VIM!

      Cheers!

      Reply
      1. Khethokuhle says:
        June 14, 2012 at 6:27 am

        This assumes that vim in intlalsed which is in a lot of ways different from vi. The purpose of this post is to educate someone on the very basics of editing a file in the event of a disaster. The concept is to prepare a customer for that one incident where a simple change can bring up the box. Vi is always intlalsed and vim not necessarily. Although, it’s a great tip on VIM!Cheers!

        Reply
    2. Jill says:
      June 14, 2012 at 11:16 am

      Thanx for that work, sustain the great fcotuinn Excellent fcotuinn, I’m planning to start off a tiny Web site Engine program perform employing your website I am hoping you take pleasure in running a blog with all the well-known BlogEngine.internet.Thethoughts you express are truly amazing. Wish you are going to correct some a lot more posts.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs
  • Resurrection of the Blog
  • Encryption type Matters with Deep Packet Inspection – solved
  • Completely off topic.. Just a personal note.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs

Recent Comments

  • Percy Kwong on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Nick Doelman on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Percy Kwong on International Text solutions – A solution
  • Muzahid Ul Islam on The Browser Wars; Which One is Best?
  • Muzahid Ul Islam on International Text solutions – A solution

Archives

  • September 2019
  • August 2019
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • January 2010
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008

Categories

  • Activism
  • All
  • Amazon S3
  • Announcements
  • Apache
  • Apple
  • Applications
  • Automation
  • AWS
  • Azure
  • Backups
  • Blogging
  • Books
  • Bootcamp
  • CentOS – RHEL
  • Cloud Computing
  • Cloudformation
  • Consulting Advice
  • Craigslist
  • Databases
  • Deep Packet Inspection
  • Doing the right thing
  • e-Book Readers
  • E-Mail
  • EC2
  • energy-efficiency
  • environment
  • Expose
  • firewalls
  • General Observations
  • Hardware
  • Hope
  • Hosting
  • IaC
  • Important things to do in life
  • Infrastructure as Code
  • Kubernetes
  • Linux
  • Media and Encoding
  • Miscellany
  • Mobile Phones
  • MySql
  • Networking
  • Performance
  • Personal
  • pfsense
  • Politics
  • Privacy
  • Redundancy
  • Routers
  • security
  • SPAM
  • Tech that doesn't work like it should
  • Tips and Tricks
  • Tools that work
  • Tout
  • Video
  • Virtual Computing
  • VOIP-Voice Over IP
  • VPN
  • Web Browsers
  • Web Hosting
  • Websites
  • Windows
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Swimminginthought | Built using WordPress and Responsive Blogily theme by Superb