[Clear, explain white! 】 VIM editor profile

Vim is a well-known powerful and highly customizable text editor similar to Vi. It has improved many new features on the basis of Vi. Vim is free software. Vim is generally regarded as one of the best vi-like editors. In fact, the real rival comes from different variants of Emacs. Emacs was selected as the winner of the Linuxworld text editing category in 1999, and vim ranked second. But in February 2000, vim won the Slashdot Beanie’s award for the best open source text editor and pushed Emacs to the second line. In general, both vim and Emacs are excellent in text editing.
vim is a text editor developed from vi. Programming functions such as code completion, compilation, and error jump are particularly abundant, and are widely used by programmers. The design concept of vim is a combination of commands. Users have learned a variety of commands for moving/jumping between texts and other common mode editing commands, and if they can be combined flexibly, they can be more than those without mode editors. Efficient text editing. At the same time, vim is similar to many shortcut settings and regular expressions, which can assist in memory, and vim is optimized for programmers.
[Speak clearly, explain clearly!] Introduction to Vim Editor

< hr>

(1) The vim editor has three modes:
command mode, insert mode, last line mode
Ctrl+Shift+T: quickly open a shell terminal
Ctrl+d: quick Delete multiple open terminals
Ctrl+PgDn: switch terminals quickly
Ctrl+PgUp: switch terminals quickly


(2) Use the format of the vim editor: # vim /path/file
[Clarify, explain!] Introduction to Vim editor


(3) When the file is just opened, it enters the command mode. We enter the [insert mode] in the following way:
[Clarify, explain!] Vim Introduction to the editor
i: Insert from the current cursor position
a: Insert from the next character of the current cursor
o: Generate a blank line on the next line of the current good, and enter insert mode
I: The cursor jumps to the beginning of this line, and enters insert mode
A: The cursor jumps to the end of this line, and enters insert mode
O: Generate a blank line on the previous line of the current line and enter insert mode
[Clarify, explain!] Introduction to Vim editor
[Clarify, explain!] Introduction to Vim editor
[Clarify, explain!] Introduction to Vim editor
< img alt="[Clarify, explain!] Introduction to Vim Editor" src="/wp-content/upload s/images/os/unix/1626797359851.png" >
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor


(4) There are also the following under [Command Mode] Operation skills:
If we insert a line of information and find that we don’t want to perform this operation, we can press u to undo in the command mode: u
When we perform the undo operation, sometimes it feels that the undo operation is not OK, I want to cancel the undo operation. You can cancel the undo operation at this time: Ctrl+r


(5) If you are in insert mode, there is no way to directly enter the last line mode, you need to insert it first The mode returns to the command mode, and then enters the [last line mode] from the command mode.
/—Enter “/” in the command mode to enter the last line mode, which means to query related information in the last line mode. At this time, press “n” on the keyboard to query the next one; press “N” on the keyboard to query the previous one.
:—Enter “:” in the command mode to enter the last line mode, and then you can proceed Edit related information.
\c—When using “/” in the last line mode to query the corresponding characters, if you need to ignore the case, you can add “\c”, then you can query to ignore the case All the character information after the end.
【Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor


(6) If you are in insert mode, edit the relevant After the information, you need to save the file. At this time, you need to enter the [last line mode] to operate:
:q!: Force exit
:wq: Save and exit
:x: Save And exit
:w /path/filename: write the current text file to the specified location (Figure 1-13 and Figure 1-14)
:r /path/file: change the text under the specified path The information is read to the position of the cursor (Figure 1-15 and Figure 1-16)
:.!ifconfig: You can press shift+! sign twice in the command mode, and then enter the command to be executed, then you can execute Read the text information of the cursor to the position of the cursor (Figure 1-17 and Figure 1-18)
[Speak clearly, explain it! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor


(7) Sometimes we are in the [last line mode] You can also set some attribute information.
:noh: You can clear the yellow information mark generated by the previous search.
:set nu: Set in the last line mode, you can display the line number of the vim editor
:set nonu: set in the last line mode, you can remove the line number of the vim editor


(8) If you want the line number attribute information of the vim editor to always exist, you can Create a .vimrc file in the current user’s home directory.
# vim .vimrc
[Clarify, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor


(9) Because the edited .vimrc file can only be The corresponding user’s home directory takes effect. If there are a large number of users in the system, I hope that all users can take effect when using the vim editor. You can edit /etc/vimrc under the root user to solve the problem.
# vim /etc /vimrc
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor


(10) Sometimes we need to carry out the information in the text For the replacement operation, the following format can be used in the [last line mode] at this time:
:s/rhce/rhca/g—Replace the text of the current line (Figure 1-25 and Figure 1-26)
:m,ns/rhce/rhca/g—Replace all information in the specified m to n lines (Figure 1-27)
:.,$-2s/rhce/rhca/g—Replace the current All specified information from line to the third-to-last line (Figure 1-28)
:%s/rhce/rhca/g—Replace the full text with the specified information (Figure 1-29)
:%s /\/rhce\//rhca/g—We need to replace the character information of “/rhce/” with “rhca”, which can be processed with the escape character of “\” (Figure 1-30)
: %s#/rhce/#rhca#g—This usage is the same as the usage in Figure 1-30.
:1000—In the last line mode, enter the number 1000 to jump directly to /etc/services Line 1000 (Figure 1-31)
【Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor


(11) In [Command Mode], there are usually the following Shortcut command:
yy—copy the current line
nyy—where n represents any number, which means the number of lines required for copying
p—paste the copied information to the cursor Paste the next line of the line
dd—cut, if you don’t paste it later, it means delete
ndd—where n represents any number, which means to cut the required number of lines from the current line Cut
dG—delete from the current line to the last line
x—delete a single character
nx—where n represents any character, which means to delete all characters from the current cursor The specified n characters
r—replace the single character at the current cursor
R—continuously replace the current cursor to any character after it, until the continuous replacement mode is exited
nG—where n Represents any number, in command mode, it means switch to the specified nth line
Shift+g— means switch to the last line
gg—Press g twice in succession, means switch to the first
Shift+zz—implemented in command mode, save and exit


(12) In [last line mode], you can also display the current file in split screen Edit
:sp—Realize split-screen display editing
Ctrl+ww— Split-screen display up and down screen jump
[Speak clearly, explain it! 】Introduction to Vim Editor


(13) Views can also be used in [Command Mode] Function, such as in the /etc/samba/smb.conf configuration file:
Ctrl+v—Enter the view mode (Figure 1-33)
x—You can delete the selected view information (Figure 1-34)
Adjust to line 320—Ctrl+v—Adjust to line 314—Shift+i—Shift+#—Keyboard Esc—Down arrow: insert comments uniformly OK (Picture 1-35)
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor
[Speak clearly, explain clearly! 】Introduction to Vim Editor

Leave a Comment

Your email address will not be published.