Linux editor - vim use

    The difference between vi/vim is simply that they are all multi-mode editors. The difference is that vim is an upgraded version of vi. It is not only compatible with all instructions of vi, but also has some new features, such as syntax highlighting and visualization. The operation can be run not only in the terminal, but also in x window, mac os, and windows.

1. Basic concepts of vim

    At present, we can master the following three modes: command mode (command mode), insert mode (Insert mode) and bottom line mode (last line mode). The functions of each mode are as follows:

Normal/Normal/Command mode (Normal mode)

    Control the movement of the screen cursor, delete characters, words or lines, move and copy a section and enter Insert mode, or go to last line mode

Insert mode

    Only in Insert mode, text input can be done. Press the Esc key to return to the command line mode, which is the most frequently used mode in the future.

last line mode

    Save or exit the file, you can also perform file replacement, find strings, list line numbers and other operations. In command mode, shift+: to enter this mode; to view all your modes: open vim, enter directly in the bottom line mode: help vim-modes

There are a total of 12 modes : six BASIC modes and six ADDITIONAL modes

2. Basic operation of vim

Enter vim, enter the vim and file name at the system prompt, and enter the vim full - screen editing screen:

 $force test.c

    But there is one thing to pay special attention to, that is, after you enter vim, you are in [normal mode], you have to switch to [insert mode] to be able to enter text

· [Normal Mode] switch to [Insert Mode]

    enter a

    enter i

    enter o

· [Insert Mode] switch to [Normal Mode]

    Currently in [Insert Mode], you can only enter text all the time. If you find a wrong word, and want to use the cursor keys to move back and delete the word, you can press Esc first 

key to go to [Normal Mode] and then delete the text. Of course, you can also delete it directly.

· [Normal Mode] switch to [Last Line Mode]

     shift+: (actually input: )

· Exit vim and save the file, in [normal mode], click the [:] colon to enter [last line mode], for example:

    :w save the current file

    :wq save and quit vim

    :q! Force quit without saving

3.vim normal mode command set

· Insert mode

    Press i to switch to insert mode (Insert mode), after pressing i to enter insert mode, the text will be inserted from the current position of the cursor;

    After pressing a to enter the insert mode, the text is inserted from the next position where the cursor is currently located;

    After pressing o to enter insert mode, a new line is inserted, and the text is entered from the beginning of the line.

Switch from insert mode to command mode

    Press Esc

· Move the cursor

    vim can be directly used on the keyboard to move up, down, left and right, but regular vim uses lowercase English letters h, j, k, l to control the cursor to move left, down, up, and right by one cell.

    Press G (to move to the end of the article)

    Press s (to move to the end of the line where the cursor is located)

    Press ^ (to move to the beginning of the line where the cursor is located)

    Press w (cursor jumps to the beginning of the next word)

    Press e (cursor jumps to the end of the next word)

    Press b (cursor returns to beginning of previous word)

    Press #l (the cursor moves to the #th position of the line, such as: 4l, 431l)

    Press gg (go to text start)

    Press shift+g (go to end of text)

    Press Ctrl+b (to move the screen "back" one page)

    Press Ctrl+f (to move the screen "forward" one page)

    Press Ctrl+u (to move the screen "back" half a page)

    Press Ctrl+d (to move the screen "forward" half a page)

· Delete text

    Each time x is pressed, delete a character at the cursor position

    #x For example: 4x means to delete 4 characters "behind (including itself)" where the cursor is located

    X Capital X, each press deletes one character "before" the cursor position

    dd delete the line where the cursor is located

    #dd deletes # lines from the line where the cursor is located

· copy

    yw Copy the characters from the cursor position to the end of the word into the buffer

    #yw copy # words into buffer

    yy Copy the line where the cursor is located to the buffer

    #yy For example: 5yy means copy 5 lines of text "count down" from the line where the cursor is located

    p Paste the character in the buffer to the position of the cursor (all y-related copy commands must be combined with "p" to complete the copy and paste function)

· Replacement

    r replace the character where the cursor is

    R replaces the character under the cursor until Esc is pressed

· Undo the last action

    u If you execute a command by mistake, you can press u immediately to return to the previous operation, and press u multiple times to restore

    Ctrl+r Undo redo

· Change

    cw change the word where the cursor is to the end of the word

    c#w For example: c3w means change 3 words

· Jump to the specified line

   Ctrl+g List the line number of the line where the cursor is located

    #G For example: 14G means move the cursor to the beginning of the 14th line of the article

4.vim last line mode command set

· List line numbers

    set nu (entering set nu will list line numbers before each line in the file)

· Jump to a line in the file

    # (# represents a number, enter a number after the colon, and then press the Enter key to jump to the line)

· Find characters

    /keyword (press the / key first, then enter the character you want to search for, if the keyword you are looking for the first time is not what you want, you can keep pressing n and you will find the keyword you want in the future)

    ? Keyword (press the ? key first, then enter the character you want to find, if the keyword you are looking for for the first time is not what you want, you can keep pressing n and it will search forward until you find the keyword you want)

· save document

    w Type the letter w after the colon to save the file

· leave vim

    q Press q to exit. If you can't leave vim, you can follow q with a! force quit vim

    wq is generally recommended to be used with w when leaving, so that the file can be saved when exiting

5. Summary of vim operation

· Three modes

   normal mode

    insert mode

    last line mode

· There are a total of 12 total modes, you can study it yourself

· vim operation

    Open, close, view, query, insert, delete, replace, undo, copy, paste, etc.

6. Simple vim configuration

   This blog post is a simple introduction to vim configuration and gcc/g++, gdb installation https://blog.csdn.net/tangduobutian/article/details/78647288





Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804143&siteId=291194637