# 4. vi编辑器使用

* vi    进入vi编辑器
* i     进入插入模式
* o     换行进入插入模式
* a     向后移动一位光标进入插入模式
* esc   进入命令模式
* :     进入底行模式(需先进入命令模式)

## 命令行模式使用

* $ 调到行尾
* gg 调到页首
* G 调到页尾
* b 移动到当前单词开始
* e 移动到当前单词结尾
* w 向后移动一个单词
* h 向前移动一个字符
* j 向下移动一行
* k 向上移动一行
* l 向后移动一个字符
* x 删除(剪贴))一个字符
* dd 删除(剪贴))一行
* u 复原操作类似于 ctrl+z
* v 选中范围 按y复制
* yy 复制一行
* yw 复制一个单词
* y$或Y 复制光标到行尾处&#x20;
* p 粘贴复制的内容在光标后
* P 粘贴复制的内容在光标前
* r 修改光标所在字符，r後接著要修正的字符
* R 进入取代状态，新增资料会覆改原先资料， 直到按\[ESC]回到指令模式下为止
* s 删除光标所在字符，并进入输入模式。
* S 删除光标所在的列，并进入输入模式。

## 底行模式

* set nu        显示行号
* set nonu      关闭行号显示
* number        跳转到第number行
* /context      跳转到指定的context的行
* %s/待替换的内容/替换结果/g    替换指定的字符串
* n1,n2s/待替换的内容/替换结果/g    替换n1,n2之间指定的字符串
* w             保存
* w filename    存入文件filename中
* w! filename   强制存入filename文件中
* q!            强制退出
* wq            保存退出 shift+zz
* q             退出
* !command      暂时离开vi编辑界面执行指定的command
* !ls /home     展开home目录下的内容


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sugar-at.gitbook.io/blog-article/linux/vi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
