為了完成交互的全屏幕編輯工作, vi 有三種模式。插入模式 (insert) 用于輸入文本。在插入模式下,你輸入的任何字符都將顯示在屏幕并存于文件。命令 (command) 模式用于大多數(shù)編輯功能。在命令模式下,所有的輸入都將產(chǎn)生一定的響應(yīng)而不是直接到文本中,例如移動(dòng)光標(biāo)、刪除一塊文本、拷貝文本等。第三個(gè)模式是執(zhí)行另 外的功能,例如查找、全局替換、處理多個(gè)文件等。這種模式是基于 ex 編輯器的。 啟動(dòng) vi
當(dāng) vi 啟動(dòng)后,默認(rèn)的模式是命令模式。按照下面的步驟試一試:輸入程序名稱啟動(dòng) vi :
If wise, a commander is able to recognize changing circumstances and toact expediently. If sincere, his men will have no doubt of the certainty ofrewards and punishments. If humane, he loves mankind, sympathizes with others,and appreciates their industry and toil. If courageous, he gains victory byseizing opportunity without hesitation. If strict, his troops are disciplinedbecause they are in awe of him and are afraid of punishment. Shen Pao-hsu … said: ‘If a general is not courageous he will be unableto conquer doubts or to create great plans.’~~~~~~~~~~~~~~~~
首先,按 5 下 h 讓光標(biāo)左移動(dòng) 5 個(gè) (如果你看到 h 跑到屏幕上了的話,一定是你忘記了按 Esc )。光標(biāo)現(xiàn)在應(yīng)該在 “plans” 中的 “p” 下面 (看下面的例子):
If wise, a commander is able to recognize changing circumstances and toact expediently. If sincere, his men will have no doubt of the certainty ofrewards and punishments. If humane, he loves mankind, sympathizes with others,and appreciates their industry and toil. If courageous, he gains victory byseizing opportunity without hesitation. If strict, his troops are disciplinedbecause they are in awe of him and are afraid of punishment. Shen Pao-hsu … said: ‘If a general is not courageous he will be unableto conquer doubts or to create great plans.’~~~~~~~~~~~~~~~
kk–光標(biāo)上移
現(xiàn)在我們來(lái)按 5 次 k 讓光標(biāo)上移 5 行。也許你該認(rèn)為應(yīng)該有快捷方式了。好,現(xiàn)在就有個(gè)簡(jiǎn)單的方法:在你要采取的 行動(dòng)前加上數(shù)字。按下 5k 你可以和按 5 下 k 有相同的結(jié) 果了。光標(biāo)現(xiàn)在該在 “he” 的”e”下了。
If wise, a commander is able to recognize changing circumstances and toact expediently. If sincere, his men will have no doubt of the certainty ofrewards and punishments. If humane, he loves mankind, sympathizes with others,and appreciates their industry and toil. If courageous, he gains victory byseizing opportunity without hesitation. If strict, his troops are disciplinedbecause they are in awe of him and are afraid of punishment. Shen Pao-hsu … said: ‘If a general is not courageous he will be unableto conquer doubts or to create great plans.’~~~~~~~~~~~~~~~~
在使用這些功能的時(shí)候有些限制的。例如使用 h 或 l 移動(dòng)光標(biāo)超過(guò)了一行文字的頭或尾,光標(biāo)將停留在頭或尾部,喇叭鳴叫提醒 你。
還有其他的類似 h 和 k 的嗎?看一看表3.2。最好的熟悉他們 的的方法是多用他們。 表 3.2. 常見的方向鍵
命令 移動(dòng) h 左一個(gè)字符 j 下一行 k 上一行 l 右一個(gè)字符 w, W 前一個(gè)單詞 (W 忽略標(biāo)點(diǎn)) b, B 后一個(gè)單詞 (B 忽略標(biāo)點(diǎn)) $ 到行尾 ^ 到行首第一個(gè)非空字符 0 行首 G 到緩沖首 nG 到第 n 行