Vi/vim Editor

Source: Internet
Author: User


VI Editor: Full-screen text editor
Vi:visual Interface, visual interface;
Vim has more new features relative to VI:
1. Syntax coloring display;
2. More orders;
3. Historical records;




Vi: Patterned text editor
    mode:
        Edit mode (command mode), default working mode;
        Insert mode (input mode), free editing of text information; "Insert" mark in the lower left corner;
        Ex mode (last line mode), for the setting of certain properties and functions of the editor itself; text editing operation is also possible;

        Other auxiliary modes:
            Replacement mode: The input information directly replaces the content of the cursor position;
            Visualization mode:

Vi/vim operation:
    1. Open the vi/vim operation interface:
        1.vi/vim command;
        2.vim file:
            1) If the file exists, use the vim editor to open the file. The default is to place the cursor at the beginning of the file, ie the first character of the first line;
            2) If file does not exist, it will be opened directly as a new file; if the save command is executed, the file will be written to disk; if not saved, the file will disappear;
        3.vim +# file:
            When opening the specified file, the cursor is positioned directly at the beginning of the #th line of the file; if the given number is larger than the number of lines of the file, the cursor directly stays at the beginning of the last line;
        4.vim + file:
            When opening the specified file, directly position the cursor at the beginning of the last line of the file;
        5.vim +/PATTERN/:
            When opening the specified file, position the cursor at the beginning of the line that was first matched by PATTERN;

    2. Close the vi/vim interface:
        Operation in ex mode:
            :q
                Close the vim editor directly, without saving the modified content;
            :q!
                Close the vim editor directly, forcibly exit without saving the modified content;
            :wq
                Save the modified content and close the vim editor;
            :wq!
                Forcibly save files that are not authorized to be changed, and force the vim editor to be closed after forced saving;

        Operation in edit mode:
            ZZ: Save and close the vim editor;
            ZQ: Do not save the modified content, directly close the vim editor;

    3. In the edit mode of vim, the way the cursor moves:
        Cursor movement in edit mode:
            1. Move by character:
                1) Left Arrow or Right Arrow;
                2) h: the cursor moves to the left; l: the cursor moves to the right;
            2. Word by word:
                w: move the cursor to the beginning of the next word;
                e: move the cursor to the suffix of the current word or the next word;
                b: move the cursor to the prefix of the previous word;
            3. In-row cursor jump:
                0: Absolute line head;
                ^: Relative line head;
                $: Absolute line end;
            4. Interline jump:
                1) Up Arrow or Down Arrow;
                2) j: move one line down; k: move one line up;
                3) #G: Move the cursor directly to the first line of the ## line;
                4) G: Move the cursor directly to the last line of the document;
                5) gg: Move the cursor directly to the first line of the document;
        Cursor movement in ex mode:
            :# : Move the cursor directly to the beginning of the specified line number "#";
            :1 : Move the cursor directly to the first line of the document;
            :$ : Move the cursor directly to the beginning of the last line of the document;

    Four. Turn the page:
        PageDown or PageUp can be used to turn pages;
        ^+f: Scroll down one page and flip forward one page; equivalent to Pgdn;
        ^+b: Turn up one page and turn back one page; equivalent to PgUp;
        ^+d: Scroll down half a page;
        ^+u: flip up half a page;

    Five. Delete characters:
        Operation in edit mode:
            1. Delete character by character:
                x: delete the character at the cursor position;
                X: Delete a character to the left of the cursor position;
            2. Delete everything that has passed during the cursor movement:
                d: Delete everything that has passed during the cursor movement:

                Dh, dl, dj, dk, dArrow, dw, de, db, dG, dgg, d0, d$, d^
                Dd: delete the line where the current cursor is located;

        Operation in ex mode:
            :d : delete the line where the cursor is located; equivalent to: .d ; where "." refers to the current line;
            :#d : Delete the ## line;
            :m,nd : delete all lines starting from the mth line and ending in the middle of the nth line;
            :m,+nd : delete the content starting from the mth line and the following n lines;
            :.,+nd : deletes the content starting from the current cursor line and the following n lines;
            :.,$d : Delete everything from the current cursor line to the end of the document;

        Note: In the operation of vim, all delete operations mean shearing at the same time;

    Copy command
        Operation in edit mode:
            y: Copy everything that has passed during the cursor movement:

            Yh, yl, yj, yk, yArrow, yw, ye, yb, yG, ygg, y0, y$, y^
            Yy: copy the line where the current cursor is located;
        Replication in ex mode:
            :y : copy the line where the cursor is located; equivalent to: .d ; where "." refers to the current line;
            :#y : Copy the ## line;
            :m,ny : copy all lines starting from the mth line to the end of the nth line;
            :m,+ny : copy the content starting from the mth line and the following n lines;
            :.,+ny : copy the content starting from the current cursor line and the following n lines;
            :.,$y : Copy everything from the current cursor line to the end of the document;

    7. Paste command:
        Operation in edit mode:
            p (Lower): If it is a copy or cut operation in the line, paste on the right side of the cursor; if it is a multi-line copy or cut operation, paste it at the bottom of the cursor;
            P (Upper): If it is a copy or cut operation in the line, paste on the left side of the cursor; if it is a multi-line copy or cut operation, paste it on the top of the cursor;
        Ex mode operation:
            :p

    Eight. Mode switching:
        The edit mode (command mode) is called the basic working mode of the vi editor; the transfer station that switches between all other modes

        1. Edit mode --> ex mode:
            ":" : means to enter the ex mode and complete the execution of the command;
            "/" or "?" : Enables the match lookup function in ex mode;
                / default is the top-down search order;
                The default is the bottom-up search order;

                The n and N commands jump between each of the matched keywords;
                n: sequential search
                N: reverse search

        2.ex mode --> edit mode:
            Double click the ESC button;
            Enter key
            Backspace key

        3. Edit mode --> input mode (insert mode):
            i, I, a, A, o, O, s, S, C, cc
            i: Start input on the left side of the cursor position;
            I: Start typing at the beginning of the line;
            a: Start input on the right side of the cursor position;
            A: Start typing at the end of the line;
            o: insert a new line below the current cursor line;
            O: Insert a new line above the current cursor line;
            s: delete the character at the cursor position and start input on the left side of the cursor;
            S: delete the line where the cursor is located, and start input at the beginning of the line;
            C: delete the cursor position until the end of the line, and start input at the end of the line;
            Cc: equivalent to the S command;

        4. Input mode --> edit mode:
            ESC

        5. Edit mode --> Replace mode:
            R: enter the replacement mode

        6. Replace Mode --> Edit Mode:
            ESC

        7. Edit mode --> Visualization mode:
            v: rectangle selection according to characters;
            V: Select a rectangle according to the unit of action;

            note:
                1) After the selection is completed, you can use the d command to delete, or you can use the y command to copy;
                2) Return to the edit mode as soon as the selection is completed;

        Note: All other modes can only be switched to and from the edit mode; if you try to switch between the two non-edit modes, you must go through the edit mode;

    Nine. Replacement order:
        r: replaces the character at the cursor position without entering the input mode;

    X. Cancellation order:
        U: Undo the operation in the current line;
        u: Cancel the previous editing operation;

        ^+r: Undo the last undo operation;

    XI. Repeat the previous editing operation:
        .

    Twelve. Multiple document editing:
        1.vim file1 file2 file3 ...
            :next View or edit the next document
            :prev View or edit the previous document
            :first View or edit the first document
            :last View or edit the last document

        2.vim -o | -O file1 file2 file3 ...
            -o: Open multiple windows horizontally
                ^+w, up arrow | down arrow: Switch between multiple windows;
            -O: Open multiple windows vertically
                ^+w, left arrow | right arrow: Switch between multiple windows;

    13. Common commands in the ex mode:
        1. Display and cancel line number:
            :set number (short for: set nu)
            :set nonumber (short for: set nonu)

        2. Turn the sensitivity of character case on or off:
            :set ignorecase (short for: set ic)
            :set noignorecase (short for: set noic)

        3. Turn automatic indentation on or off:
:set autoindent (short for: set ai)
             :set noautoindent (short for: set noai)

         4. Turn syntax coloring on or off:
             :syntax on
             :syntax off

         5. Turn on or off the search highlight:
             :set hlsearch
             :set nohlsearch (short for: nohl)

         6. Save as:
             :w /path/to/somewhere
             :m,nw /path/to/somewhere

         7. Read the content directly from other files and add it to the current file:
             :r /path/from/somefile

         8. Interact with the shell, call the shell command
             :!COMMAND

     Fourteen.vimtutor
       Can view the above 13 commands 


Vi/vim Editor


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.