Usage of vi/vim editor


1. Introduction to vi/vim editor

  • vi/vim is the most commonly used and best-used text editor for Linux and Unix character interfaces, and vim is an advanced version of vi.
  • vi/vim is functionally equivalent to Notepad under the Windows graphical interface. However, as a non-graphical editor used under the character interface, it can not only edit general text files, but also edit configuration files of Linux systems and various servers.
  • vi/vim is also a powerful programming tool, you can use it to write shell scripts, c, c++, java, php codes, etc.
    掌握vi/vim命令并进行操作是至关重要的。

2. Three working modes and mutual conversion of vi/vim editor

insert image description here

3. Common commands of vi/vim editor

1. The command to switch from command mode to edit mode

Order effect
a Append text after cursor
A Append text at the end of this line
i insert text before cursor
I Insert text starting on this line
o Insert a new line under the cursor
O Insert a new line at the cursor
一般常用i进入

2. Copy and paste and delete commands in command mode

  • yy: copy the current line
  • nyy: means to copy n lines backwards from the current line
  • p: Paste below the current line
  • dd: delete the current line
  • ndd: delete n lines from the current line
  • dG: Delete from the current line to the last line of the file
  • u: Undo the last operation

3. Quickly move the cursor command in the command mode

  • gg: go to the first line
  • G: go to the last line
  • Home: the beginning of the line
  • End: end of line
  • Page Up: page up
  • Page Down: Turn down the page
    以上四个就是键盘上下左右键,需要配合Fn使用。

4. Save and exit commands in command mode

  • ZZ: save changes and exit

5. Commands in last line mode

  • :set number (or nu) Enter: display line number
  • :set nonumber (or nonu) Enter: cancel the display of the line number
  • :n carriage return: go to the nth line
  • /String to search Enter查出后输入N,继续往上查找即反向查找。输入n,继续往下查找即正向查找
    使用vim打开文件搜索字符串时,会把符合条件的全部高亮显示;使用vi打开时,光标会定位到第一个。

6. Save and exit vi/vim commands in the last line mode

  • :w Enter: Save changes
  • :w [new file name] Enter: save as the specified file
  • :wq Enter: save changes and exit
  • :wq! Enter: force to save and exit
  • :q Enter: exit
  • :q! Enter: force exit without saving

4. Matters needing attention

insert image description here


Guess you like

Origin blog.csdn.net/ATTAIN__/article/details/124288209