Vim 中删除文本的详细练习指导
以下是关于如何在 Vim 中删除文本的详细练习指导,您可以根据这些步骤在 practicedeleting.txt
文件中进行练习。
练习目标
本练习的目标是熟悉在文件中删除文本的操作,以及练习使用 [count][operator]{motion}
的模式。
练习步骤
1. 打开 practicedeleting.txt
文件
- 开始命令行会话:打开终端。
- 导航到文件所在目录:
cd Downloads/vimclass vim practicedeleting.txt
2. 删除单个字符
-
移动到文件的第三行:
- 可以按
j
键向下移动,或使用3gg
,3G
, 或:3<ENTER>
跳转到第三行。
- 可以按
-
删除拼写错误的字符:
- 找到单词 "mistakke" 中的多余字母 "k",将光标放在 "k" 下方,按
x
删除该字符。
编辑前:
First, fix this spelling mistakke.
编辑后:
First, fix this spelling mistake.
- 找到单词 "mistakke" 中的多余字母 "k",将光标放在 "k" 下方,按
-
移动到第四行:
- 删除每个单词中的重复字母,使用
x
删除光标下的字符。
编辑前:
Fixx theese allso.
编辑后:
Fix these also.
- 删除每个单词中的重复字母,使用
-
移动到下一行:
Delete this text with the X command.
- 将光标移动到行末,可以按
l
键多次,或使用$
键。使用X
删除所有文本,最后按x
删除句号:
编辑后:
(空行)
- 将光标移动到行末,可以按
3. 删除文本区域
-
移动到下一行:
Who let the dogs out? cats
- 将光标移到问号后的空格,删除该行余下文本,可以使用
d$
或D
。
编辑后:
Who let the dogs out?
- 将光标移到问号后的空格,删除该行余下文本,可以使用
-
移动到第 43 行的开头:
- 使用
43gg
。 - 删除该行的第一个单词,可以使用
dw
或dW
,例如:
编辑前:
Far far away, behind the wild mountains, far from the countries Vokalia and
编辑后:
far away, behind the wild mountains, far from the countries Vokalia and
- 使用
-
删除第二个单词:
- 现在的行是:
away, behind the wild mountains, far from the countries Vokalia and
- 使用
dW
删除 "away, "。
编辑后:
behind the wild mountains, far from the countries Vokalia and
-
删除 "the" 前的单词:
- 将光标定位到 "the" 的开头,使用
db
或dB
删除第一个单词。
编辑后:
the wild mountains, far from the countries Vokalia and
- 将光标定位到 "the" 的开头,使用
-
删除 "the wild ":
- 使用
2dw
。
编辑后:
mountains, far from the countries Vokalia and
- 使用
-
删除 "mountains, far ":
- 使用
d2W
。
编辑后:
from the countries Vokalia and
- 使用
4. 删除行
-
删除当前行:
- 使用
dd
删除当前行。
当前行:
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove
- 使用
-
删除多行:
- 使用
3dd
删除三行。
要删除的行:
Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.
- 使用
-
重复命令:
- 删除下三行,按
.
重复上一个删除命令。
被删除的行:
A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
- 删除下三行,按
5. 保存更改或放弃
- 保存更改并继续编辑:
- 使用
:w<ENTER>
。
- 使用
- 保存并退出:
- 输入
:wq<ENTER>
。
- 输入
- 放弃更改:
- 输入
:q!<ENTER>
。
- 输入
6. 自由练习
- 如果您觉得可以,尝试在文件中自由删除文本,运用您所学的知识和技巧。
通过上述步骤,您将熟悉 Vim 中删除文本的各种方法,希望您在实践中能够熟练掌握这些命令,提高编辑效率!
迷茫的人生,需要不断努力,才能看清远方模糊的志向!