Getting to know vim for the first time

vim working mode

1. Command mode

The command mode is the mode that vim enters by default after opening the file. No characters can be inserted in this mode, but the working mode of vim can be set
: set Specify information
: set nu Add line number
: set nonu Cancel the line number
: set cursorline Add the line mark
:set mouse=a Add mouse selection

Note: The working method of setting vim directly in vim is a temporary setting, that is to say, when vim is closed, the setting is invalid

      If you want to set it permanently, you need to write "/etc/vimrc". This file is also the configuration file of vim

2. How to manage characters in command mode
Press "x"
    to delete the character where the cursor is,
press "u"
    undo to restore
press "ctrl+r"
    redo to undo and restore
press "y" to
    copy
    "yw" ##copy a word
    "yl" ## Copy a letter
    "yy" ##Copy a whole line
    "y5y" ##Copy 5 lines
"c"
    cut
    "cw" ##cut a word
    "cl" ##cut a letter
    "cc" ##cut A whole line
    "c5c" ##cut 5 lines
    Note: "When you use C to cut, it will enter the insert mode. If you want to paste, you need to exit the insert mode and press <ESC> and then press P"

"d"
    to delete
    "dw" # #delete a word
    "dl" ##delete a letter
    "dd"##Delete a whole line of
    "d5d" ##Delete 5 lines of
"p"

    paste

3. Visual operation of vim

(1). The basic operation of the visual mode
cannot be operated with the mouse to select the area in vim.
If you want to operate a certain area, you need to enter the visual mode.
In the command mode, "ctrl + v" can enter the visual mode and
press "Up|Down|Left|Right" move the cursor to select the area, and press the corresponding operation key to operate the selected area

(2). Batch add characters in visual mode
[1]. Keep the cursor on the first row of the column where you want to add the character
[2]. Move the cursor to select the column where the added character is
[3]. "I" enters the insert mode
【4】.Write the character to be inserted

[5]. Press "ESC" to exit the insert mode, and the characters are added in batches successfully


4. Character replacement of vim ####
%s/original characters/new characters/g #Full text replace
1,5s/original characters/new characters/g #Replace characters from 1 to 5 lines

g #Replace all the keywords that appear, if you don't add "g", only the first one that doesn't appear on the line will be replaced

The effect of executing %s/sbin/passwd/g

 5. Vim total character search and cursor movement
[1]. Character search
/keyword
n ​​## Down to match keyword
N ## Up to match key sub

2. Cursor movement
: number ##The cursor moves quickly to the specified Line
gg ##The cursor moves to the first line of the file

G ##The cursor moves to the last line of the file

 6.vim edits multiple files at the same time########
:sp filename
ctrl + w up #Cursor enters the upper file window
ctrl + w down #Cursor enters the lower file window


########## ########## Insert mode ######################
"i" #Insert the character
"I" at the cursor position #The cursor position Insert character
"o" at the beginning of the line #Insert character
"O" in a new line next to the line where the cursor is located #Insert "s" as a new line above the line where the
cursor is #Delete the character where the cursor is and insert the character
"S" #Delete Insert the character
"a" at the line where the cursor is placed # Insert "A" after the character under the
cursor # Insert character at the end of the line where the cursor is placed




################## Exit mode ###########################################################################################################################################################################################################################
When
vim enters the file Have operations on the contents of the file but do not want to save and exit
: wq #Save and exit normally
:wq! #Forcibly save and exit, only valid for the root user or the owner of the file





Guess you like

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