Use of Vim

Source: Internet
Author: User
Tags strcmp

Three modes of VIM:
    • Command mode

      ESC enters in any mode

    • Edit mode

      Command mode--"edit mode"

      • I: Before the character of the current cursor

      • A: After the character of the current cursor

      • O: Create a new row below the line where the current cursor is located

      • I: At the beginning of the line where the cursor is currently located

      • A: At the end of the line where the current cursor is located

      • O: Create a new row above the line where the current cursor is located

    • Visualization mode

      Command mode, press V to enter

    • In non-edit mode, Ctrl + V

Basic operations
    • Open File

      Vim/path/to/somefile

      • Vim +#: Open the file and locate it on line #
      • Vim +: Open the file and navigate to the last line
      • Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN
    • Close File

      Command-line mode

      : Q exit

      : Wq Save and exit

      : q! Do not save and exit

      : W Save

      : w! Forcibly saved

      : Wq---: X

      : Save SaveAs as

    • Move cursor

      • Character-by-word movement

        H: Left L: Right J: down K: Upper

      • Move in a word unit

        W: Move to the beginning of the next word

        E: Jumps to the ending of the current or next word

        B: Jump to the beginning of the current or previous word

      • In-line jump

        0: The absolute beginning

        ^: first non-whitespace character at the beginning of a line

        $: absolute end of line

      • Inline jump

        #G: Jump to Line #;

        G: Last line

        GG: to the first line

  • Flip Screen

    CTRL+F: Flip one screen down

    Ctrl+b: Turn up one screen

    Ctrl+d: Flip Down half screen

    Ctrl+u: Flip up half screen

  • Delete a single character

    X: Delete a single character at the cursor location

    #x: Remove the total # characters from the cursor and backwards

  • Delete command: D (the use of Copy command y is the same as this)

    DD: Deletes the current cursor in the row

    #dd: Delete the line containing the line of the current cursor;

    DFK Remove from cursor to K-letter position

    FK cursor moves to the next K-letter position

    Press in command-line mode: Enter STARTADD,ENDADDD (delete Staradd to EndAdd)

    .: Indicates when the forward

    $: Last line

    +#: Down # line

  • Paste Command P

    P: If you delete or copy to a whole line, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full line, paste it behind the character of the cursor;

    P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it in front of the character in the cursor;

  • Replacement: R

    R: Replacement mode

  • Undo Edit Operation U

    U: Undo previous edit Operation Continuous u command to undo previous n edits

    #u: Undo Recent # edits directly

    Undo the most recent undo action: Ctrl+r

  • Visual operation (in command mode v Enter)

    Match selection: such as if (strcmp ("ABC", szstr) = = 0) cursor at position a

    I "-" selected ABC, removed ""

    A "-" check "ABC"

    i)-"ABC" selected, Szstr

    2a)-"Checked (strcmp (" ABC ", szstr) = = 0)

  • Enter block Action (Ctrl + V Enter)

    Move arrow key selection block

    Add content to the front of each line of the cursor: Select Block-->i (capital I) and enter what you want to add-->[esc]--> carriage return

    Add content after each line of cursor: Select Block-->a--> Enter what you want to add-->[esc]--> enter

    Indent left and right: Select Blocks < and >

    Auto indent: Select block =

  • Repeats the previous edit operation.

  • Find

    :/pattern

    :? PATTERN

    N,n move to the next/previous matching place

  • Use Vim to edit multiple files

    Vim FILE1 FILE2 FILE3

    : Next switches to the next file

    :p Rev Switch to the previous file

    : Last switch to final file

    : first to switch to file one

    Exit: QA All exits

  • Split-screen display of a file

    Ctrl+w, S: Horizontal splitter window

    Ctrl+w, V: Vertical splitter window

    Toggle cursor between windows: Ctrl+w, ARROW

    : QA Closes all windows

  • Edit multiple files in a split window

    Vim-o: Horizontal Split display

    Vim-o: Vertical Split display

  • Fills the contents of another file in the current file

    : R/path/to/somefile

  • Interacting with the shell

    :! COMMAND

  • Show or suppress line numbers

    : Set Number (: Set NU)

    : Set Nonu

  • Show ignore or differentiate character case

    : Set ignorecase (: Set IC)

    : Set Noic

  • Set Auto Indent

    : Set Autoindent (: Set AI)

    : Set Noai

  • Find text to highlight or cancel

    : Set Hlsearch

    : Set Nohlsearch

  • Syntax highlighting

    : Syntax on

    : Syntax off

Configuration file
    • /ETC/VIMRC: Global configuration file
    • ~/.VIMRC: Personal profile, if not, you can create it yourself, be sure to create it under your home directory
Vim Quick Check Table

Use of 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.