Vim Usage Tips

Source: Internet
Author: User
Tags line editor

Pictures worth a thousand UNIX commands and options:

I draw this to my students each semester and they seem to grasp VI afterwards.

VI is a finite state machine with only three states.

========   ======

VIM has 3 modes of Operation:input mode, Command mode & Ex mode.

Input Mode -everything that's type, all keystrokes is echoed on the screen.

Command mode or Escape mode -everything the type in this mode is interpreted as a Command.

ex Mode -This is another editor, ex. It's a line editor. It works per line or based on a range of lines. In this mode, a : appears at the bottom. This is the ex editor.

In order to exit Vim, you can exit while your is in either the ex mode or in the command mode. You cannot exit Vim when your is in input mode.

Exiting from ex Mode

    1. You need to is sure that is in the Command mode. To does that, simply press the Escape key.

    2. Go to the ex mode by pressing the : key

    3. Use any of the following combinations on ex mode to exit:

:q-Quit :q! -quit without saving :wq -save & Quit or write & quit :wq! -Same as WQ, but force write incase File permissions is readonly :x -write & Quit :qa -quit all. Useful when multiple files is opened like:vim abc.txt xyz.txt

Exiting from Command mode

    1. Press the Escape key. You probably has done this already if you is in command mode.

    2. Press Capital ZZ ( shift zz )-Save & Exit

    3. Press Capital ZQ ( shift zq )-Exit without saving.

Upon starting, vi goes into COMMAND mode, where can type short, few character commands, blindly. You know what is doing, this isn ' t for amateurs.

When you want to actually edit the text, you should go to INSERT mode with some one-character command:

    • I:go to INSERT in the the the cursor
    • I:go to INSERT mode at the beginning
    • A:append after the cursor
    • A:append at the end of line
    • O: Open A new line below the
    • O: Open A new line in the place of the

Now, answering the question:exiting.

You can exit VI from EX mode:

    • Q:if Haven ' t made any modifications, or saved them beforehand
    • q!: Ignores any modifications and quit
    • Wq:save and quit
    • X:this is equal to Wq

W and x Accept the file name parameter. If you started vi with a filename, you need not give it here again.

At last, the most important:how can you reach EX mode?

EX mode is for long commands so can see typing at the bottom line of the. From COMMAND mode, you push colon,: and a colon would appear at the bottom line, where can type the above commands.

From INSERT mode, you need to push ESC, i.e. the Escape button, going to COMMAND mode, and then:to go to EX mode.

If you is unsure, push ESC and that would bring you to command mode.

So, the robust method is Esc-:-x-enter which saves your file and quits.

Vim Usage Tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.