全屏幕编辑器 VS 行编辑器
全屏幕编辑器就是指用户工作的时候他可以在终端上看到他所处理的文件的全部或者部分。例如在一个25行的显示终端上,他可以看到文档中的24行。在编辑的时候,你并非在处理硬盘上的实际文件,而是你的文件的一个拷贝。这个拷贝一般叫做缓存。所有对文件的增加、修改、删除操作都是对缓存的操作,只有当你保存的时候,实际的文件才有改变。所以你一定听说过要经常保存你正处理的文件的建议。这个建议对于所有类似处理的程序都有用。
If wise, a commander is able to recognize changing circumstances and to
act expediently. If sincere, his men will have no doubt of the certainty of
rewards and punishments. If humane, he loves mankind, sympathizes with others,
and appreciates their industry and toil. If courageous, he gains victory by
seizing opportunity without hesitation. If strict, his troops are disciplined
because they are in awe of him and are afraid of punishment.
Shen Pao-hsu ... said: 'If a general is not courageous he will be unable
to conquer doubts or to create great plans.'
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"art1" 8 lines, 576 characters
为了完成交互的全屏幕编辑工作, vi 有三种模式。插入模式 (insert) 用于输入文本。在插入模式下,你输入的任何字符都将显示在屏幕并存于文件。命令 (command) 模式用于大多数编辑功能。在命令模式下,所有的输入都将产生一定的响应而不是直接到文本中,例如移动光标、删除一块文本、拷贝文本等。第三个模式是执行另外的功能,例如查找、全局替换、处理多个文件等。这种模式是基于 ex 编辑器的。
启动 vi
当 vi 启动后,默认的模式是命令模式。按照下面的步骤试一试:输入程序名称启动 vi :
If wise, a commander is able to recognize changing circumstances and to
act expediently. If sincere, his men will have no doubt of the certainty of
rewards and punishments. If humane, he loves mankind, sympathizes with others,
and appreciates their industry and toil. If courageous, he gains victory by
seizing opportunity without hesitation. If strict, his troops are disciplined
because they are in awe of him and are afraid of punishment.
Shen Pao-hsu ... said: 'If a general is not courageous he will be unable
to conquer doubts or to create great plans.'
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
hh--光标左移
首先,按 5 下 h 让光标左移动 5 个 (如果你看到 h 跑到屏幕上了的话,一定是你忘记了按 Esc )。光标现在应该在 "plans" 中的 "p" 下面 (看下面的例子):
If wise, a commander is able to recognize changing circumstances and to
act expediently. If sincere, his men will have no doubt of the certainty of
rewards and punishments. If humane, he loves mankind, sympathizes with others,
and appreciates their industry and toil. If courageous, he gains victory by
seizing opportunity without hesitation. If strict, his troops are disciplined
because they are in awe of him and are afraid of punishment.
Shen Pao-hsu ... said: 'If a general is not courageous he will be unable
to conquer doubts or to create great plans.'
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
kk--光标上移
现在我们来按 5 次 k 让光标上移 5 行。也许你该认为应该有快捷方式了。好,现在就有个简单的方法:在你要采取的行动前加上数字。按下 5k 你可以和按 5 下 k 有相同的结果了。光标现在该在 "he" 的"e"下了。
If wise, a commander is able to recognize changing circumstances and to
act expediently. If sincere, his men will have no doubt of the certainty of
rewards and punishments. If humane, he loves mankind, sympathizes with others,
and appreciates their industry and toil. If courageous, he gains victory by
seizing opportunity without hesitation. If strict, his troops are disciplined
because they are in awe of him and are afraid of punishment.
Shen Pao-hsu ... said: 'If a general is not courageous he will be unable
to conquer doubts or to create great plans.'
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
在使用这些功能的时候有些限制的。例如使用 h 或 l 移动光标超过了一行文字的头或尾,光标将停留在头或尾部,喇叭鸣叫提醒你。
还有其他的类似 h 和 k 的吗?看一看表3.2。最好的熟悉他们的的方法是多用他们。
表 3.2. 常见的方向键
命令 移动
h 左一个字符
j 下一行
k 上一行
l 右一个字符
w, W 前一个单词 (W 忽略标点)
b, B 后一个单词 (B 忽略标点)
$ 到行尾
^ 到行首第一个非空字符
0 行首
G 到缓冲首
nG 到第 n 行