Linux text editor Vim

1. Vim working mode

    1. First enter or create a text document

    2. Enter insert mode to enter text in a text document

    3. ESC key to enter command mode for text editing settings

    4. Exit text

Features:

Full screen text editor for linux and unix, built to edit and display text files, Vim has no menus but commands.


Enter: vi + already exists or create a file name

Insert the command iao:

Press b piece, not input b, but wait for input

Press o to enter insert mode

Esc returns to command mode

Set line numbers in command mode: set nu

Save and exit wq can be used when editing some configuration files or scripts

2. Insert command

    a - insert after the character under the cursor

    A - Insert at the end of the line where the cursor is located

    i - insert before the character under the cursor

    I - Insert at the beginning of the line where the cursor is located

    o - insert a new line under the cursor

    O - Insert a new line at the cursor

3. Positioning command

    :set nu - set line number

    :set nonu - cancel line numbering

    gg/G - to the first line/to the last line

    nG - to the nth line

    :n - go to the nth line

    $ - move to end of line

    0 (zero) - move to end of line

4. Delete command

    x - delete the character where the cursor is located

    nx - delete n characters after the cursor

    dd - delete the line where the cursor is located, ndd deletes n lines

    dG - delete the line where the cursor is located to the end of the file

    D - delete the content from the cursor to the end of the line

    :n1,n2d - delete lines in the specified range

5. Copy and paste commands

    yy - copy the current line

    nyy - copy n lines below the current line

    dd - cut and paste current line

    ndd - clip n lines below the current line

    p/P - Paste under or on the line where the current cursor is located

6. Replace and cancel commands

    r - cancel the character where the cursor is located

    R——Replace characters from where the cursor is, press ESC to end [replace according to the input content]

    u - cancel the previous operation

7. Search and search replace commands

/string - search for the specified string, ignore case when searching: set ic

n - search for the next occurrence of the specified string

:%s old/new/g - replace the specified string in full text



8. Save and Exit Commands

:w - save changes

:w_new_filename - save as specified file

:wq - save changes and exit

ZZ - shortcut key, save changes and exit

:q! - quit without saving changes

:wq! - save changes and exit (available for file author and root)

 9. Enter search results into text

Import command execution result: r ! command

Define shortcut keys: map shortcut keys to start commands

Example: map ^p I#<ESC>

       :  map ^B 0x

Open the file and import the entered filename into the location of the ad.

: ! date View time

:r! date import the result of the current command execution to the current cursor position


Ctrl-v +p pay attention to the font color


Remove the first character at the beginning of the line because the comment characters are in the first position at the beginning of the line


Enter command mode after inserting email address at the beginning of the line

10. Continuous annotation

Consecutive comment lines: n1,n2s/^/#/g

                  :n1,n2s/^#//g

                  :n1,n2s/^/\/\//g

Replace: ab mymail [email protected]


The first line to the fourth line continuous comment ^ represents the character at the beginning of the line

uncomment


1,4s/separation^start of line/separation\/escape\/escape/separation g

1.4s / ^ / \ / \ // g

Type mynail in the text with a space or enter and it will change to my email








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325171071&siteId=291194637
Recommended