This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.

Introduction to the

Vim is a well-known powerful and highly customizable text editor similar to Vi, with many improvements and additions. (Mainly Vi/Vim is a Linux command line essential software).

Download & Install

download

Can go towebsitedownload

The installation

  • Windows exe executable file can be installed
  • Linux

Ubuntu: sudo apt-get install vim -gTK centos: yum -y install vim*

  • Mac

Download the binary file Macvim

Vim keys you figure

Pictures fromCenalulu. Making. IO/Linux/all – v…

  • The English version

  • The Chinese version of

An introduction to

Vi/VIM three modes

  • Command Mode

Launching puts you in command mode, where the keyboard is a command to the editor, not a character. Common commands:

  1. iEnter edit mode
  2. :The baseline command mode is displayed
  3. xDeletes the character of the current cursor position
  • Insert mode

Similar to Windows notepad, shortcuts are also basically universal, not to mention.

  • Last Line Mode

The bottom line command mode has many useful functions, the most basic characters are as follows:

  1. wsave
  2. qexit
  3. !mandatory

You can combine commands, such as wq! Forcibly save and exit.

The relationship is as follows: Image fromrunoob

Enter the vim

Vim filenameCopy the code

The file name must be complete, including the suffix. If the file exists, edit it. Otherwise, a new file is created.

Common commands

The cursor

way instructions
h/please The cursor moves left
j/left The cursor down
k/write The cursor move up
l/- The cursor moves to the right
digitaln+ The above four commands Perform n length movement
Ctrl+f Move up one page =Page Down
Ctrl+b Move down one page =Page Up
Ctrl+d Down half a page
Ctrl+u Move up half a page
+ Move to the next line that is not empty
- Move to a non-empty line
n<space> Move the cursor right n character units on this line
0/Home Moves to the first character of the line
$/End Move to the end of the line
H Move to the top of the screen
M Move to the center of the screen
L Move to the bottom of the screen
G Move to the last row
digitaln+G Let’s go to row NTH
gg If I go to the first row, that’s 1g
digitaln+Enter Down n lines

The search to replace

way instructions
/word Search down for the word word
? word Search up for the word word
n Repeat the search from the previous step
N Repeat the previous search in reverse
:n1,n2s/word1/word2/g Replace word1 from n1 to n2 with word2, s for search, and g for global
:n1,n2s/word1/word2/gc C (confirm) is added to confirm the replacement

Delete, copy and paste

way instructions
x/X X is equivalent to del, x is equivalent to backspace, and can be followed by a number, such as nx, to delete n characters backwards
dd Delete the entire line
ndd Delete n rows down
d1G Delete the row to the first line
dG Delete the row to the last line
d$ Deletes the cursor to the end of the line
d0 Deletes the cursor to the top of the line
yy Copy the bank
nyy Copy n rows down
y1G Copy the row to the first row
yG Copy the row to the last row
y0 Copy the character to the beginning of the line
y$ Copy the character to the end of the line
p/P P pasted backwards, p pasted forwards
J Merge the next line
u undo
Ctrl+r redo
. Repeat

Switch to edit mode

way instructions
i The input mode
r Replace mode
Esc Exit edit mode

The bottom line pattern

Press in command mode:Enter baseline mode

way instructions
! Enforce the command and use it with other commands
:w Write data can be connected!
:q Exit. You can take it!
:! command Temporarily leave vim and run command
:set nu According to the line Numbers
:set nonu Cancel the line number display

Q&A

The Windows garbled

  1. Open gVim with administrator privileges (it may not save otherwise)
  2. Go to Edit-Launch Settings

3. Press theiKey to enter edit mode and insert at the beginning of the line:

set fileencodings=utf-8,ucs-bom,cp936,big5
set fileencoding=utf-8
Copy the code

As is shown in4. Press the:Key To switch to baseline command mode 5. Enterw!Forced save 6. Enterq!Forced out of

conclusion

Vi/Vim is powerful, but not so powerful that it is irreplaceable, but it is a very powerful text editor in command line mode and is good for servers.