• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Tips and Tricks HQ

  • Home
  • Projects
    • All Projects
    • Simple WP Shopping Cart
    • WP Express Checkout Plugin
    • Accept Stripe Payments
    • WP Download Monitor
    • Easy HTTPS Redirection
    • WP Security and Firewall Plugin
    • WP eStore Plugin
    • WP Affiliate Platform
    • WP eMember
  • Products
    • All Products
    • Checkout
  • Support
    • Support Portal
    • Customer Only Forum
    • WP eStore Documentation
    • WP Affiliate Software Documentation
    • WP eMember Documentation
  • Contact

UNIX vi commands – take advantage of the UNIX vi editor

Home » Blog » UNIX vi commands – take advantage of the UNIX vi editor

Last updated: March 22, 2010





The UNIX vi commands listed on this page which handles navigation, cursor movement, searching, editing, inserting text, using auto-complete, cut copy and paste operations etc in vi are useful for taking advantage of the UNIX vi editor.

vi (Visual Editor) is the default editor that comes with the UNIX operating system.

The UNIX vi editor has two modes of operation:
1.Command mode (commands which cause action to be taken on the file – Press the ‘i’ character to change to Insert mode).
2.Insert mode (entered text is inserted into the file – Press the <Esc> (Escape) key to go to the command mode).

When using vi, keep in mind that vi is case sensitive. Over time I have learned that the ‘Escape’ key is king in vi editor.



Start and exit commands

To open a file in the vi editor to start editing, simply type in ‘vi <filename>’ in the command prompt.
e.g. prompt>vi tmp.txt

To quit vi, type one of the following commands in the command mode and press ‘Enter’.
Exit vi, writing out modified file – : x
Exit vi, writing out modified file – :wq
Simply quit vi – :q
Force exit from vi even though changes haven’t been saved – :q!

Cursor Navigation in vi editor

By character – h, j, k, l

Unix vi editor movement keys
Unix vi editor movement keys

First/Last character in a line – 0/$
First non-blank character in a line – ^
First non-blank character on last line – G
First non blank character on line n – nG
Move to matching comment/Bracket/Brace – %
Forward to beginning of next word – w
Back to beginning of current/previous word – b
Forward to beginning of next sentence – )
Back to beginning of current/previous sentence – (
Forward to next blank line – }
Back to previous blank line – {

Screen Navigation in vi editor

Move window one line down – CTRL-E
Move window one line up – CTRL-Y
Move window one page down – CTRL-F
Move window one page up – CTRL-B
Mark position as n – mn
Go to marked position n – ‘n

Search and Substitute in vi editor

Search forward for pattern – /pattern
Search backwards pattern – ?pattern
Substitute next pattern with string – :s/pattern/string
Substitute pattern with string on current line – :s/pattern/string/g
Substitute pattern with string in file – :%s/pattern/string/g

Search Patterns

Match beginning of line – ^
Match end of line – $
Match start of word – \<
Match end of word – \>
Match any single character – .
Match character in range – [a-z]
Match character not in range – [^a-z]
Match 0 or more of the preceding atom – *

Changing to Insert Mode in vi editor

Insert text after cursor – a
Insert text before curser – i
Append text at end of line – A
Insert text before first non-blank character – I
Insert text above the current line – o
Insert text below the current line – O

Cut, Copy and Paste operation in vi editor

Cut text from curser to motion – dmotion
Copy text from curser to motion – ymotion
Cut current line – dd
Copy current line – yy
Paste after curser – p
Paste before curser – P
To join the next line – J

Advanced commands

Start shell – :shell
Execute command within a shell – :! Command
Read in another file – :r file
Read in results of a command – :r! command
Filter motion through command – !motion command

Misc vi Commands

Change current line – cc
Undo last change – u
Repeat last command – .

Please feel free to leave your favourite vi commands in the comments area below if it’s not on this page.

Related Posts

  • Basic UNIX Commands List
  • List of useful and frequently used DOS Commands

Tech Tips UNIX,  Unix Commands,  Useful Commands

Reader Interactions

Comments (9 responses)

  1. mahender says:
    April 19, 2015 at 10:21 pm

    I absolutely love vi. With vi editor, I generally notice only two types of reactions – people either absolutely love it or they absolutely hate it. There is rarely any middle ground.

    Vi has a big learning curve and it is only after considerable time and effort does one one realize the magic of vi.

  2. Manoj says:
    February 26, 2012 at 9:12 am

    hey, its very useful and easy to understand article…
    many thanks..

  3. Amanda Gordon says:
    June 8, 2011 at 4:53 pm

    I absolutely love vi. With vi editor, I generally notice only two types of reactions – people either absolutely love it or they absolutely hate it. There is rarely any middle ground.

    Vi has a big learning curve and it is only after considerable time and effort does one one realize the magic of vi.

  4. Priya says:
    February 24, 2011 at 8:51 pm

    hey, its very useful and easy to understand article…

    many thanks..

  5. Deepika says:
    September 4, 2010 at 12:33 am

    Thanks for your detailed list of commands for vi editor. Will you also write an article on emacs editor?

  6. rahul says:
    June 26, 2009 at 1:27 am

    i want vi to search a key word and delete the whole line…

  7. Erik says:
    June 19, 2009 at 9:15 pm

    I would like to have the shopping cart just like your first screenshot. A list where people can add the quantity they want. But I don’t see a way to set this up? Can you please advise?

  8. admin says:
    June 17, 2009 at 11:41 pm

    @Sanjay, To get out of the Vi mode you simply need to press the ‘Esc’ key then enter ‘:’ and ‘q’. What do you mean by “without executing my commands”?

  9. sanjay says:
    June 17, 2009 at 5:17 pm

    Hi,

    I want to know how can i get out of the vi mode to the command prompt, when i had come from the command prompt(pressing esc key,v @ command prompt) without executing my commands.

    pls. reply.

    Rgds,
    Sanjay Sule

Leave a Reply

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

Primary Sidebar

Featured & Popular Articles

Video Answers to Top WordPress QuestionsWordPress Optimization Tips and Tricks for Better Performance and SpeedEssential WordPress Security Tips - Is Your Blog Protected?WordPress Simple PayPal Shopping Cart PluginTop 15 Search Engine Optimization (SEO) Techniques I Forget to DoList of the Best and Must Use WordPress PluginsHow do I Start a Blog and Make Money Online?Good Domain Name Picking Tips for Your Blog SetupFind Out Which WordPress Web Hosting Company Offers the Cheapest and Reliable Web Hosting Solution

Featured WordPress Plugins

WP Express Checkout Plugin
wordpress estore plugin
wordpress membership plugin
wordpress affiliate plugin

Recent Posts

  • How to Use Browser Developer Tools to Inspect Elements and [...]
  • Accept Donations via PayPal from Your WordPress Site Easil [...]
  • Buy Now Button Graphics for eCommerce Websites [...]
  • Subscription Button Graphics for eCommerce Websites [...]
  • Adding PayPal Payment Buttons to Your WordPress Sidebar Ea [...]

Comment & Socialize

  • @Rob, We have just released ...
    - admin
  • I installed the plugin a co ...
    - Rob
  • @Sebastian, We've released ...
    - admin
  • I've used this plugin on a ...
    - Sebastian Djupsjöbacka
  • @John, this plugin doesn't ...
    - admin

Check out our solutions

View our WordPress plugin collection and start using them on your site.

Our WordPress Solutions

Footer

Company

  • About
  • Privacy Policy
  • Terms and Conditions
  • Affiliate Login

Top WordPress Plugins

  • Simple Shopping Cart
  • PayPal Donations
  • WP Express Checkout
  • WP eStore
  • WP eMember

Blogging Tips

  • How to Start a Blog
  • Selecting a Good Domain
  • Cheap WP Hosting
  • WP Video Tutorials
  • Simple SEO Tips

Search


Keep In Touch

Copyright © 2025 | Tips and Tricks HQ