Skip to Content
《学习 vi 和 Vim 编辑器》,第 8 版
book

《学习 vi 和 Vim 编辑器》,第 8 版

by Arnold Robbins, Elbert Hannah
May 2025
Beginner to intermediate
548 pages
5h 59m
Chinese
O'Reilly Media, Inc.
Content preview from 《学习 vi 和 Vim 编辑器》,第 8 版

第 4 章. 基础知识之外

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

您已经了解了基本编辑命令i,a,c,dy 。本章将扩展您已经掌握的编辑知识。内容包括

  • 附加编辑功能说明,并回顾一般命令格式

  • vi 和 Vim 命令行选项,包括打开文件进行编辑的不同方法

  • 利用寄存器来存储删除信息

  • 在文件中标记您的位置

  • 其他高级编辑

更多命令组合

第 2 章 "简单编辑 "您学习了编辑命令cdy ,以及如何将它们与动作和数字相结合(如2cw4dd )。在第 3 章 "匆忙移动 "您又增加了许多动作命令。虽然可以将编辑命令与动作相结合对您来说并不是一个新概念,但表 4-1还是提供了一些您以前没有见过的编辑选项。

表 4-1. 更多编辑命令
改变 删除 复制 从光标到...

cH

dH

yH

屏幕顶部

cL

dL

yL

屏幕底部

c+

d+

y+

下一行

c5|

d5|

y5|

当前行第 5 列

2c)

2d)

2y)

之后的第二句

c{

d{

y{

上一段

c/pattern

d/pattern

y/pattern

图案

cn

dn

yn

下一个模式

cG

dG

yG

文件结束

c13G

d13G

y13G

第 13 行

请注意,表 4-1中的所有序列都遵循两种一般模式中的一种:

(指令(数字(文本对象)

(数字(命令(文本对象)

这里的命令cdy 中的一个。文本对象是移动命令。

vi 命令的一般形式将在第 2 章中讨论。您还可以参考表2-2和表2-3

启动 vi 和 Vim 时的选项

到目前为止,您已经在 shell 中用命令调用了编辑器:

$ vi file

或与

$ vim file

vim 命令还有其他一些有用的选项。你可以直接按照特定行号或模式打开文件。还可以以只读模式打开文件。另一个选项可以恢复系统崩溃时正在编辑的文件的所有更改。

下节所述的选项既适用于vi,也适用于 Vim。

前进到特定地点

开始编辑现有文件时,可以调用该文件, ,然后移动到第一个出现的模式或特定行号。您也可以在命令行中通过搜索或行号指定第一次移动。使用-c command;为了与早期版本的vi 向后兼容,也可以使用+command:

$ vim -c n file

打开第n 行的文件

$ vim -c /pattern file

模式首次出现时打开文件

$ vim + file

在最后一行打开文件

在文件实践中,要打开文件并直接前进到包含Screen 字样的行,请输入以下内容:

按键 成果

$ vim -c /Screen practice

With a screen editor you can scroll
the page, move the cursor, delete
lines, and insert characters, while
seeing the results of your edits as
you make them. Screen editors are
very popular, since they allow you
to make changes as you read

vim 命令中输入-c /pattern 直接转到包含Screen 的行。

正如您在本例中看到的,您的搜索模式并不一定位于屏幕顶部。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

《Asterisk:权威指南》第 5 版

《Asterisk:权威指南》第 5 版

Jim Van Meggelen, Russell Bryant, Leif Madsen
图解大模型 : 生成式AI 原理与实战

图解大模型 : 生成式AI 原理与实战

Jay Alammar, Maarten Grootendorst

Publisher Resources

ISBN: 9798341657885