Vim's simple usage and simple commands

Source: Internet
Author: User

Vim is a very powerful text editor in Linux. Proficient in using vim editor can do more with less in making scripts and editing texts.


The vim editor has three modes:

Command mode

By default, when you use vim to edit text, you can directly enter the command mode. In the secondary mode, you can view the contents of the text, you can copy the content in the text, but you cannot modify the content in the text. The letters and characters on the keyboard. Will be treated as a command by the vim editor and not a character entered



Edit mode

In the command mode, the letter a, the letter i, enters the edit mode, in which the content in the text can be changed and characters are added.



Extended command mode

In command mode, enter the extended command mode through ":". In this mode, you can enter various commands including Linux commands. In this mode, each character also has its own command effect.



In the edit mode and the extended command mode, the ESC key can be used to return to the command mode, but the extended command mode cannot be entered in the edit mode, and the edit mode cannot be entered in the extended command mode.



The relationship between the three command modes is as follows









Interface in command mode





Interface in extended mode









Some common commands in command mode





    l Cursor right shift
    g cursor down
    h cursor left shift
    k cursor up
    i changes to edit mode in front of the character where the current cursor is located
    a after the current cursor character, turn to edit mode
    o New line below the current cursor line, and change to edit mode
    I is converted to edit mode at the beginning of the line where the current cursor is located.
    A is converted to edit mode at the end of the line where the current cursor is located.
    O at the top of the current cursor line, create a new line and switch to edit mode

    w moves to the beginning of the next word
    e jump to the end of the current or next word
    b jump to the beginning of the current or previous word
    #w移动#字
    0 absolute line head
    $absolute line ending
    The first non-whitespace character at the beginning of the line
    #G转到第#行
    The first line of the content displayed by gg on the current screen
    G last line
    x delete the character behind the character where the cursor is located
    #x Delete the total number of characters at the cursor and backwards
    Dd delete the line where the cursor is located
    # Delete the line where the cursor is and the ## line down





Common commands under extended commands





    :q exit
    :wq save and exit
    :q! Do not save and exit, forcibly retreat
    :w save but not quit
    :w! Forcibly saved

   :w{filename} saves a new text file to the currently edited text.



Simple usage and simple commands for vim


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.