Basic operation of Vim

Source: Internet
Author: User
Tags save file

Basic operation of Vim
  • Start vim
    Enter the command in the terminal: Vim in the terminal interface or gvim separate out a window.
  • Text input
    Enter the character "a" or "I" in normal mode to enter text editing mode.
  • File Save
    After the text is entered, press ESC, enter normal mode, and then enter the colon ":" and then enter "W test.txt" so that the content can be written to the Test.txt.
  • Exit vim
    Enter command line mode
    Enter ": Wq" to save and exit;
    Enter ": Q" is the exit;
    Enter ": Wq test.txt" to write the content to Test.txt and save the exit;

    Vim's often-used command vim is designed to perform all of Vim's operations quickly with the keyboard only, so there are many VIM commands. The following are some of the most common commands for VIM (the following command is entered in normal mode, and a command prefixed with a colon indicates execution in command mode )
  • Enter VIM
  • vim, start vim
  • Vim file name , start vim and open or create a new file
    # # # cursor Movement

    1. Mobile

    h, move one character to the left
    l, move one character to the right
    J, move down one line
    K, move up one line

    2, beginning line end

    0 or , move to line start (note is number 0)
    $ or , move to end of line
    ^, move to the first non-whitespace character on the current line
    g_, moves to the last non-whitespace character on the current line

    3. Moving words and ending

    W, move to the beginning of the next word
    b, move to the beginning of the last word
    e, move to the ending of the next word
    GE, move to the beginning of the last word

    4, jump to specify the line

    NG, jumps to the specified nth row
    GG, jump to the first line

    5. Screen adaptation

    G, jump to the last line
    M, jumps to the middle row of the current screen
    L, jump to the end line of the current screen
    ZZ, placing the current line in the center of the screen

    Search 1, single character

    FX, looking for the next character on the current line X
    Fx, finding the previous character X on the current line

    2. String

    /, search down. Type/, enter the string you want to search for, and then go back in. []^%/?~$ These have a special meaning, if you want to search for these characters themselves, you need to precede them with a backslash /, search upward. Type first? , and then enter the string you want to search for, and then press enter. []^%/?~$ These have a special meaning, if you want to search for these characters themselves, you need to precede the backslash # # # #3, Word
    Place your cursor on word, * For backward lookup, #代表向前查找
    Vim searches for characters that are generally highlighted, and if you want to jump to the next matching string, type N, or N if you skip to the previous one.
    /<word>, find only word this word-/<word>, find word only word

    Move to a matching parenthesis

    %, the default matching brackets include three types: () []{}. when multi-level can be quickly matched, if you want to add a new match symbol "<>", you can do the following command: Set mps+=<:>

Jump to modify Point

'., jump to the last modified line
.**,跳到最后修改的那一点 **gd**,跳转到文件第一次出现的地方,通常是变量定义的地方 **ma**,用字母a标记当前光标所在的位置,这里a可以是任意字母 ** a, jump to a place
"to jump to the last cursor position

Basic editing command form in vim: Edit Command + scope

Delete: D copy: Y change: C (change meaning to delete and insert)

Delete 1, line

DD, delete the current line,3dd Delete 3 rows
DW, delete the first letter (including spaces) of the cursor position to the next word
CW, removes the first letter (excluding spaces) from the position of the cursor to the next word
DFX, delete the position of the cursor where it appears in the next character X of the bank

2. Words

Daw, delete a word (including the ending space)
DIW, delete a word (not including the ending space)

3. Words

das, delete a sentence

4, character

x, delete the characters under the current cursor
NX, removing n characters after the cursor, such as 3x
NX, delete the first n characters of the cursor, such as 3X

Copy/paste

Nyy, puts the current n rows into the buffer
yy, copy a whole line
p, place the contents of the buffer below the current line
P, place the contents of the buffer above the current position

Undo/Redo

u, restore the previous command
., repeat a command

Replace [range]substitute/from/to/[flags]1. Replace the selected range with the command line

"-" represents the current line; "$" stands for the last line; "%" represents all operations, and if you do not specify a range, only the objects of the bank are replaced
"+-" relative offset, for example: its equivalent description is to type "5:" in the current line, in the lower left corner of vim there will be an equivalent description ".,. +4", meaning to represent a substitution operation within the range from the current row down to the 5th row of the current row.
Substitute/from/to can be replaced with S.
Flags This additional parameter includes I (case-insensitive) g (replaces all strings in a row) p (lists all rows that have been changed) C (requires user confirmation before performing each substitution) If you do not specify a parameter, only the first discovered target string in a row is replaced
: s/p1/p2/g, replaces all P1 in the current row with P2
%s/p1/p2/, replace all current text
: n1,n2s/p1/p2/g, all P1 in line N1 to N2 are replaced with P2
:.,. +4s/p1/p2/g, replaces all P1 in the current line at the cursor until 4 rows below the current line with P2
: g/p1/s//p2/g, replace all P1 in the file with P2

2. Character substitution

RA, replacing the characters under the current cursor with the letter A
R, can implement multi-character substitution, in fact, is the SHIFT+R key

Uppercase and lowercase conversions

Under Visual, type HJKL selected area
U, lowercase to uppercase
u, uppercase to lowercase
u, lowercase to uppercase - u, lowercase to uppercase
--------

Words are padded

Ctrl-p Word completion in insert mode (find words forward)
Ctrl-n Word completion in insert mode (find words backwards)
---------

Folded
    • In normal mode, move to the desired line, type zf18j (fold cursor below 18 lines)
    • In visual mode, select the text you want to collapse with JKLH, type ZF,zo, open fold; ZR, open all folds; Zc, close folding, ZM, close all folds

      Snap To

      left-justified: {Range}left[margin],range is the range of rows that need to be aligned, margin is the leftmost distance from the window at the beginning of the alignment. Example:: 90,100 left 0 justified
      Right alignment: {Range}right[width],range is the line range that needs to be aligned, width is the length of each line after alignment

      Save File

      : w, disk
      : W file name , disk to file

      Exit vim

      : Q, exit
      : Wq, save exit
      : q!, forced exit

Basic operation 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.