為了完成交互的全屏幕編輯工作, vi 有三種模式。插入模式 (insert) 用于輸入文本。在插入模式下,你輸入的任何字符都將顯示在屏幕并存于文件。命令 (command) 模式用于大多數編輯功能。在命令模式下,所有的輸入都將產生一定的響應而不是直接到文本中,例如移動光標、刪除一塊文本、拷貝文本等。第三個模式是執行另 外的功能,例如查找、全局替換、處理多個文件等。這種模式是基于 ex 編輯器的。 啟動 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 讓光標左移動 5 個 (如果你看到 h 跑到屏幕上了的話,一定是你忘記了按 Esc )。光標現在應該在 “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–光標上移
現在我們來按 5 次 k 讓光標上移 5 行。也許你該認為應該有快捷方式了。好,現在就有個簡單的方法:在你要采取的 行動前加上數字。按下 5k 你可以和按 5 下 k 有相同的結 果了。光標現在該在 “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.’~~~~~~~~~~~~~~~~
在使用這些功能的時候有些限制的。例如使用 h 或 l 移動光標超過了一行文字的頭或尾,光標將停留在頭或尾部,喇叭鳴叫提醒 你。
還有其他的類似 h 和 k 的嗎?看一看表3.2。最好的熟悉他們 的的方法是多用他們。 表 3.2. 常見的方向鍵
命令 移動 h 左一個字符 j 下一行 k 上一行 l 右一個字符 w, W 前一個單詞 (W 忽略標點) b, B 后一個單詞 (B 忽略標點) $ 到行尾 ^ 到行首第一個非空字符 0 行首 G 到緩沖首 nG 到第 n 行