Introduction to the use of vim and a complete list of commands (systematic learning day 3)

                                                                                   Lazy Yangyang thanks everyone for your attention and support~ 

Table of contents

Preface

1. Introduction to the use of vim

2. Complete list of commands

1. Command mode

(1) Copy (used with the paste command p)

(2) Cut

(3) Paste

(4) Delete

(5) Undo/Restore

 (6) Shortcut keys for editing commands 

2. Bottom line mode (:xxx command)

(1) Save/exit file operation

(2) Search 

(3) Replacement

(4) Line number display

(5) File switching

(6) Split window (very efficient when editing multiple files)

3.Edit mode

Summarize


Preface

Vim (Vi IMproved) is a powerful text editor that is considered an improved version of the Vi editor. It is one of the most popular text editors on Unix systems and can be used on other operating systems as well.


1. Introduction to the use of vim

The vim editor has three modes:

1. Command mode

2.Edit mode

3. Bottom row mode

How to switch modes:

(1) In command mode, press a、i、o、Athe key to enter the edit mode
(2) In edit mode, press escto return to the command mode
(3) In the command mode, :after input, enter the bottom line mode
(4) In bottom line mode, press escor delete: and the command after it to return to command mode.

2. Complete list of commands

1. Command mode

(1) Copy (used with the paste command p)

shortcut key Function
yy Copy the content of the line where the cursor is located
y Copy the content selected by the mouse
n(number)+yy Copy the line where the cursor is located, n represents the number of lines, you can copy the content of the line where the cursor is and the following lines
is Copy the word at the cursor position

(2) Cut

shortcut key Function
dd Cut the line where the cursor is
n(number)+dd Based on the line where the cursor is located (including the current line), cut down the specified number of lines
D Cut the line where the cursor is

(3) Paste

shortcut key Function description
p Paste the contents of the clipboard after the cursor
P (capital) Paste the contents of the clipboard in front of the cursor

(4) Delete

shortcut key Function
x   Delete the character at the cursor position
X ( capital Delete the character before the cursor
dd Delete the line where the cursor is. After deletion, the next line moves up.
D Delete the content from the cursor position to the end of the line. After deletion, the next line will not move up.
n.d Delete n lines of text after the current line (including this line)
dw Move the cursor to the beginning of a word to delete it
dG Delete everything from the line under the cursor to the end of the file
:a1,a2d ( bottom row mode ) Delete the text content from line a1 to line a2

(5) Undo/Restore

shortcut key Function
u Cancel
ctrl+r recover
U( capital ) Undo all edits

 (6) Shortcut keys for editing commands 

shortcut key Function
↑ or ctr + p Previous command
↓orctr+n next command
ctr + b Move to the beginning of the command line
ctr + e Move to the end of the command line
ctr + ← one word to the left
ctr + → one word to the right

2. Bottom line mode (:xxx command)

(1) Save/exit file operation

Order Function
:q Exit Vim editor without saving
:q! Do not save and force quit Vim editor
:w Save but do not exit the Vim editor
:w! Force saving of text
:x Save the text and exit the Vim editor
:wq  Save and exit the Vim editor
:wq! Save and force quit the Vim editor
ZZ Exit the Vim editor directly

(2) Search 

shortcut key Function
/abc Search the string abc forward from the cursor position
/^abc Find lines starting with abc
/abc$ Find lines ending with abc
?abc Find the string abc backward from the cursor position

(3) Replacement

shortcut key  Function
:s/a1/a2 Replace the first qualified content in the line where the current cursor is located
:s/a1/a2/g Replace all a1 in the current cursor line with a2
:%s/a1/a2 Replace the first matching content in all lines
:%s/a1/a2/g Replace all matching content in all lines
:n1,n2 s/a1/a2 Replace the first a1 in lines n1 to n2 in the file with a2
:n1,n2 s/a1/a2/g 将文件中 n1 到 n2 行中所有 a1 都用 a2 替换

(4)行号显示

  1. 行号显示 : :set nu
  2. 取消行号显示: :set nonu

(5)文件切换

快捷键 功能
:files 查看当前已经打开的所有文件
:open +  文件名 切换到指定文件
:bp 切换到上一个文(back previous)
:bn 切换到下一个文件(back next)

(6) 分割窗口(多文件编辑时很高效

分割窗口快捷键:  :vs +文件名

注意:分割窗口可以同时查看和编辑多个文件,互相之间不会影响

3.编辑模式

快捷键 功能
 在当前光标所在位置插入,光标后的文本相应向右移动
在光标所在行的行首插入,行首是该行的第一个非空白字符,相当于光标移动到行首执行 i 命令
在光标所在行的下插入新的一行。光标停在空行首,等待输入文本
O(大写 在光标所在行的上插入新的一行。光标停在空行的行首,等待输入文本
a 在当前光标所在位置之后插入
A 在光标所在行的行尾插入,相当于光标移动到行尾再执行 a 命令
esc键 退出编辑模式回到命令模式


总结

      本篇文章详细地讲了关于vim的使用介绍以及命令大全和许多快捷键的使用和分析,希望能够帮到大家!

      以后还会给大家展现更多关于Ubantu的其他重要的基础知识,感谢大家支持懒大王!

      希望这篇博客能给各位朋友们带来帮助,最后懒大王请来过的朋友们留下你们宝贵的三连以及关注,感谢你们!
 

Guess you like

Origin blog.csdn.net/weixin_58070962/article/details/132815985