VI高手之路

vi —— 終端中的編輯器

目標從

  • vi 簡介

  • 打開和新建文件

  • 三種工作模式

  • 常用命令

  • 分屏命令

  • 常用命令速查圖

01. vi 簡介

1.1 學習 vi 的目的

  • 在工作中,要對 服務器 上的文件進行 簡單 的修改,可以使用 ssh 遠程登錄到服務器上,并且使用 vi 進行快速的編輯即可

  • 常見需要修改的文件包括:

    • 源程序

    • 配置文件,例如 ssh 的配置文件 ~/.ssh/config

  • 在沒有圖形界面的環(huán)境下,要編輯文件,vi 是最佳選擇!
  • 每一個要使用 Linux 的程序員,都應該或多或少的學習一些 vi 的常用命令

1.2 vi 和 vim

  • 在很多 Linux 發(fā)行版中,直接把 vi 做成 vim 的軟連接

vi

  • viVisual interface 的簡稱,是 Linux最經(jīng)典 的文本編輯器

  • vi 的核心設計思想 —— 讓程序員的手指始終保持在鍵盤的核心區(qū)域,就能完成所有的編輯操作

[圖片上傳失敗...(image-acfed2-1547089150961)]

  • vi 的特點:

    • 沒有圖形界面功能強大 的編輯器

    • 只能是編輯 文本內(nèi)容,不能對字體、段落進行排版

    • 不支持鼠標操作

    • 沒有菜單

    • 只有命令

  • vi 編輯器在 系統(tǒng)管理、服務器管理 編輯文件時,其功能永遠不是圖形界面的編輯器能比擬的

vim

vim = vi improved

  • vim 是從 vi 發(fā)展出來的一個文本編輯器,支持 代碼補全、編譯錯誤跳轉(zhuǎn) 等方便編程的功能特別豐富,在程序員中被廣泛使用,被稱為 編輯器之神

查詢軟連接命令(知道)

  • 在很多 Linux 發(fā)行版中直接把 vi 做成 vim 的軟連接

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="true" cid="n70" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> # 查找 vi 的運行文件
?
which vi ls -l /usr/bin/vi
ls -l /etc/alternatives/vi ls -l /usr/bin/vim.basic
?

查找 vim 的運行文件

which vim ls -l /usr/bin/vim
ls -l /etc/alternatives/vim ls -l /usr/bin/vim.basic </pre>

02. 打開和新建文件

  • 在終端中輸入 vi 在后面跟上文件名 即可

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="true" cid="n75" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> $ vi 文件名</pre>

  • 如果文件已經(jīng)存在,會直接打開該文件

  • 如果文件不存在,會新建一個文件

2.1 打開文件并且定位行

  • 在日常工作中,有可能會遇到 打開一個文件,并定位到指定行 的情況

  • 例如:在開發(fā)時,知道某一行代碼有錯誤,可以 快速定位 到出錯代碼的位置

  • 這個時候,可以使用以下命令打開文件

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="true" cid="n89" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> $ vi 文件名 +行數(shù)</pre>

提示:如果只帶上 + 而不指定行號,會直接定位到文件末尾

2.2 異常處理

  • 如果 vi 異常退出,在磁盤上可能會保存有 交換文件

  • 下次再使用 vi 編輯該文件時,會看到以下屏幕信息,按下字母 d 可以 刪除交換文件 即可

提示:按下鍵盤時,注意關閉輸入法

[圖片上傳失敗...(image-1c7169-1547089150960)]

03. 三種工作模式

  • vi 有三種基本工作模式:

    1. 命令模式

      • 打開文件首先進入命令模式,是使用 vi入口

      • 通過 命令 對文件進行常規(guī)的編輯操作,例如:定位、翻頁、復制粘貼、刪除……

      • 在其他圖形編輯器下,通過 快捷鍵 或者 鼠標 實現(xiàn)的操作,都在 命令模式 下實現(xiàn)

    2. 末行模式 —— 執(zhí)行 保存退出 等操作

      • 要退出 vi 返回到控制臺,需要在末行模式下輸入命令

      • 末行模式vi出口

    3. 編輯模式 —— 正常的編輯文字

[圖片上傳失敗...(image-b0286b-1547089150960)]

提示:在 Touch Bar 的 Mac 電腦上 ,按 ESC 不方便,可以使用 CTRL + [ 替代

末行模式命令

命令 英文 功能
w write 保存
q quit 退出,如果沒有保存,不允許退出
q! quit 強行退出,不保存退出
wq write & quit 保存并退出
x 保存并退出

04. 常用命令

命令線路圖

  1. 重復次數(shù)

    • 在命令模式下,先輸入一個數(shù)字,再跟上一個命令,可以讓該命令 重復執(zhí)行指定次數(shù)
  2. 移動和選擇(多練

    • vi 之所以快,關鍵在于 能夠快速定位到要編輯的代碼行

    • 移動命令 能夠 和 編輯操作 命令 組合使用

  3. 編輯操作

    • 刪除、復制、粘貼、替換、縮排
  4. 撤銷和重復

  5. 查找替換

  6. 編輯

學習提示

  1. vi 的命令較多,不要期望一下子全部記住,個別命令忘記了,只是會影響編輯速度而已

  2. 在使用 vi 命令時,注意 關閉中文輸入法

4.1 移動(基本)

  • 要熟練使用 vi,首先應該學會怎么在 命令模式 下樣快速移動光標

  • 編輯操作命令,能夠和 移動命令 結(jié)合在一起使用

1) 上、下、左、右

命令 功能 手指
h 向左 食指
j 向下 食指
k 向上 中指
l 向右 無名指

[圖片上傳失敗...(image-7d738-1547089150960)]

2) 行內(nèi)移動

命令 英文 功能
w word 向后移動一個單詞
b back 向前移動一個單詞
0 行首
^ 行首,第一個不是空白字符的位置
$ 行尾

3) 行數(shù)移動

命令 英文 功能
gg go 文件頂部
G go 文件末尾
數(shù)字gg go 移動到 數(shù)字 對應行數(shù)
數(shù)字G go 移動到 數(shù)字 對應行數(shù)
:數(shù)字 移動到 數(shù)字 對應行數(shù)

4) 屏幕移動

命令 英文 功能
Ctrl + b back 向上翻頁
Ctrl + f forward 向下翻頁
H Head 屏幕頂部
M Middle 屏幕中間
L Low 屏幕底部

4.2 移動(程序)

1) 段落移動

  • vi 中使用 空行 來區(qū)分段落

  • 在程序開發(fā)時,通常 一段功能相關的代碼會寫在一起 —— 之間沒有空行

命令 功能
{ 上一段
} 下一段

2) 括號切換

  • 在程序世界中,()、[]{} 使用頻率很高,而且 都是成對出現(xiàn)的
命令 功能
% 括號匹配及切換

3) 標記

  • 在開發(fā)時,某一塊代碼可能需要稍后處理,例如:編輯、查看

  • 此時先使用 m 增加一個標記,這樣可以 在需要時快速地跳轉(zhuǎn)回來 或者 執(zhí)行其他編輯操作

  • 標記名稱 可以是 a~z 或者 A~Z 之間的任意 一個 字母

  • 添加了標記的 行如果被刪除,標記同時被刪除

  • 如果 在其他行添加了相同名稱的標記,之前添加的標記也會被替換掉

命令 英文 功能
mx mark 添加標記 x,x 是 a~z 或者 A~Z 之間的任意一個字母
'x 直接定位到標記 x 所在位置

4.3 選中文本(可視模式)

  • 學習 復制 命令前,應該先學會 怎么樣選中 要復制的代碼

  • vi 中要選擇文本,需要先使用 Visual 命令切換到 可視模式

  • vi 中提供了 三種 可視模式,可以方便程序員選擇 選中文本的方式

  • ESC 可以放棄選中,返回到 命令模式

命令 模式 功能
v 可視模式 從光標位置開始按照正常模式選擇文本
V 可視行模式 選中光標經(jīng)過的完整行
Ctrl + v 可視塊模式 垂直方向選中文本
  • 可視模式下,可以和 移動命令 連用,例如:ggVG 能夠選中所有內(nèi)容

4.4 撤銷和恢復撤銷

  • 在學習編輯命令之前,先要知道怎樣撤銷之前一次 錯誤的 編輯動作!
命令 英文 功能
u undo 撤銷上次命令
CTRL + r redo 恢復撤銷的命令

4.5 刪除文本

命令 英文 功能
x cut 刪除光標所在字符,或者選中文字
d(移動命令) delete 刪除移動命令對應的內(nèi)容
dd delete 刪除光標所在行,可以 ndd 復制多行
D delete 刪除至行尾

提示:如果使用 可視模式 已經(jīng)選中了一段文本,那么無論使用 d 還是 x,都可以刪除選中文本

  • 刪除命令可以和 移動命令 連用,以下是常見的組合命令:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n420" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> * dw # 從光標位置刪除到單詞末尾

  • d0 # 從光標位置刪除到一行的起始位置
  • d} # 從光標位置刪除到段落結(jié)尾
  • ndd # 從光標位置向下連續(xù)刪除 n 行
  • d代碼行G # 從光標所在行 刪除到 指定代碼行 之間的所有代碼
  • d'a # 從光標所在行 刪除到 標記a 之間的所有代碼</pre>

4.6 復制、粘貼

  • vi 中提供有一個 被復制文本的緩沖區(qū)

    • 復制 命令會將選中的文字保存在緩沖區(qū)

    • 刪除 命令刪除的文字會被保存在緩沖區(qū)

    • 在需要的位置,使用 粘貼 命令可以將緩沖區(qū)的文字插入到光標所在位置

命令 英文 功能
y(移動命令) copy 復制
yy copy 復制一行,可以 nyy 復制多行
p paste 粘貼

提示

  • 命令 d、x 類似于圖形界面的 剪切操作 —— CTRL + X

  • 命令 y 類似于圖形界面的 復制操作 —— CTRL + C

  • 命令 p 類似于圖形界面的 粘貼操作 —— CTRL + V

  • vi 中的 文本緩沖區(qū)同樣只有一個,如果后續(xù)做過 復制、剪切 操作,之前緩沖區(qū)中的內(nèi)容會被替換

注意

  • vi 中的 文本緩沖區(qū) 和系統(tǒng)的 剪貼板 不是同一個

  • 所以在其他軟件中使用 CTRL + C 復制的內(nèi)容,不能在 vi 中通過 P 命令粘貼

  • 可以在 編輯模式 下使用 鼠標右鍵粘貼

4.7 替換

命令 英文 功能 工作模式
r replace 替換當前字符 命令模式
R replace 替換當前行光標后的字符 替換模式
  • R 命令可以進入 替換模式,替換完成后,按下 ESC 可以回到 命令模式

  • 替換命令 的作用就是不用進入 編輯模式,對文件進行 輕量級的修改

4.8 縮排和重復執(zhí)行

命令 功能
>> 向右增加縮進
<< 向左減少縮進
. 重復上次命令
  • 縮排命令 在開發(fā)程序時,統(tǒng)一增加代碼的縮進 比較有用!

    • 一次性 在選中代碼前增加 4 個空格,就叫做 增加縮進

    • 一次性 在選中代碼前刪除 4 個空格,就叫做 減少縮進

  • 可視模式 下,縮排命令只需要使用 一個 > 或者 <

在程序中,縮進 通常用來表示代碼的歸屬關系

  • 前面空格越少,代碼的級別越高
  • 前面空格越多,代碼的級別越低

4.9 查找

常規(guī)查找

命令 功能
/str 查找 str
  • 查找到指定內(nèi)容之后,使用 Next 查找下一個出現(xiàn)的位置:

    • n: 查找下一個

    • N: 查找上一個

  • 如果不想看到高亮顯示,可以隨便查找一個文件中不存在的內(nèi)容即可

單詞快速匹配

命令 功能
* 向后查找當前光標所在單詞
# 向前查找當前光標所在單詞
  • 在開發(fā)中,通過單詞快速匹配,可以快速看到這個單詞在其他什么位置使用過

4.10 查找并替換

  • vi 中查找和替換命令需要在 末行模式 下執(zhí)行

  • 記憶命令格式:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n559" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> :%s///g</pre>

1) 全局替換

  • 一次性替換文件中的 所有出現(xiàn)的舊文本

  • 命令格式如下:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n566" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> :%s/舊文本/新文本/g</pre>

2) 可視區(qū)域替換

  • 先選中 要替換文字的 范圍

  • 命令格式如下:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n573" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> :s/舊文本/新文本/g</pre>

3) 確認替換

  • 如果把末尾的 g 改成 gc 在替換的時候,會有提示!推薦使用!

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n578" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> :%s/舊文本/新文本/gc</pre>

  1. y - yes 替換

  2. n - no 不替換

  3. a - all 替換所有

  4. q - quit 退出替換

  5. l - last 最后一個,并把光標移動到行首

  6. ^E 向下滾屏

  7. ^Y 向上滾屏

4.11 插入命令

  • vi 中除了常用的 i 進入 編輯模式 外,還提供了以下命令同樣可以進入編輯模式:
命令 英文 功能 常用
i insert 在當前字符前插入文本 常用
I insert 在行首插入文本 較常用
a append 在當前字符后添加文本
A append 在行末添加文本 較常用
o 在當前行后面插入一空行 常用
O 在當前行前面插入一空行 常用

[圖片上傳失敗...(image-9c214e-1547089150959)]

演練 1 —— 編輯命令和數(shù)字連用

  • 在開發(fā)中,可能會遇到連續(xù)輸入 N 個同樣的字符

Python 中有簡單的方法,但是其他語言中通常需要自己輸入

  • 例如:********** 連續(xù) 10 個星號

要實現(xiàn)這個效果可以在 命令模式

  1. 輸入 10,表示要重復 10 次

  2. 輸入 i 進入 編輯模式

  3. 輸入 * 也就是重復的文字

  4. 按下 ESC 返回到 命令模式,返回之后 vi 就會把第 2、3 兩步的操作重復 10

提示:正常開發(fā)時,在 進入編輯模式之前,不要按數(shù)字

演練 2 —— 利用 可視塊 給多行代碼增加注釋

  • 在開發(fā)中,可能會遇到一次性給多行代碼 增加注釋 的情況

Python 中,要給代碼增加注釋,可以在代碼前增加一個 #

要實現(xiàn)這個效果可以在 命令模式

  1. 移動到要添加注釋的 第 1 行代碼,按 ^ 來到行首

  2. CTRL + v 進入 可視塊 模式

  3. 使用 j 向下連續(xù)選中要添加的代碼行

  4. 輸入 I 進入 編輯模式,并在 行首插入,注意:一定要使用 I

  5. 輸入 # 也就是注釋符號

  6. 按下 ESC 返回到 命令模式,返回之后 vi 會在之前選中的每一行代碼 插入 #

05. 分屏命令

  • 屬于 vi 的高級命令 —— 可以 同時編輯和查看多個文件

5.1 末行命令擴展

末行命令 主要是針對文件進行操作的:保存、退出、保存&退出、搜索&替換、另存、新建、瀏覽文件

命令 英文 功能
:e . edit 會打開內(nèi)置的文件瀏覽器,瀏覽要當前目錄下的文件
:n 文件名 new 新建文件
:w 文件名 write 另存為,但是仍然編輯當前文件,并不會切換文件

提示:切換文件之前,必須保證當前這個文件已經(jīng)被保存!

  • 已經(jīng)學習過的 末行命令
命令 英文 功能
:w write 保存
:q quit 退出,如果沒有保存,不允許退出
:q! quit 強行退出,不保存退出
:wq write & quit 保存并退出
:x 保存并退出
:%s///gc 確認搜索并替換

在實際開發(fā)中,可以使用 w 命令 階段性的備份代碼

5.2 分屏命令

  • 使用 分屏命令,可以 同時編輯和查看多個文件
命令 英文 功能
:sp [文件名] split 橫向增加分屏
:vsp [文件名] vertical split 縱向增加分屏

1) 切換分屏窗口

分屏窗口都是基于 CTRL + W 這個快捷鍵的,w 對應的英文單詞是 window

命令 英文 功能
w window 切換到下一個窗口
r reverse 互換窗口
c close 關閉當前窗口,但是不能關閉最后一個窗口
q quit 退出當前窗口,如果是最后一個窗口,則關閉 vi
o other 關閉其他窗口

2) 調(diào)整窗口大小

分屏窗口都是基于 CTRL + W 這個快捷鍵的,w 對應的英文單詞是 window

命令 英文 功能
+ 增加窗口高度
- 減少窗口高度
> 增加窗口寬度
< 減少窗口寬度
= 等分窗口大小

調(diào)整窗口寬高的命令可以和數(shù)字連用,例如:5 CTRL + W + 連續(xù) 5 次增加高度

06. 常用命令速查圖

[圖片上傳失敗...(image-f98175-1547089150959)]

vimrc

  • vimrcvim 的配置文件,可以設置 vim 的配置,包括:熱鍵配色、語法高亮插件

  • Linuxvimrc 有兩個位置,家目錄下的配置文件優(yōu)先級更高

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="true" cid="n818" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 1.125rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(255, 255, 255); position: relative !important; color: rgb(122, 122, 122); padding: 0.5rem 1.125em 0.5rem 0px; margin-bottom: 0.88em; border: 1px solid rgb(122, 122, 122); line-height: 1.5rem; width: inherit; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> /etc/vim/vimrc
~/.vimrc</pre>

  • 常用的插件有:

    • 代碼補全

    • 代碼折疊

    • 搜索

    • Git 集成

    • ……

  • 網(wǎng)上有很多高手已經(jīng)配置好的針對 python 開發(fā)的 vimrc 文件,可以下載過來直接使用,或者等大家多 Linux 比較熟悉后,再行學習!

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,712評論 0 5
  • 一、Python簡介和環(huán)境搭建以及pip的安裝 4課時實驗課主要內(nèi)容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 6,333評論 0 10
  • 曾經(jīng)使用了幾年多的Vim,手冊也翻過一遍。雖然現(xiàn)在不怎么用vim了,曾經(jīng)的筆記還是貼出來,與喜歡vim的朋友分享。...
    Sylar丶閱讀 974評論 0 0
  • 終端中的編輯器-VI 目標 vi 簡介 打開和新建文件 三種工作模式 常用命令 分屏命令 常用命令速查圖 01. ...
    熊貓人和熊貓君閱讀 991評論 0 1
  • 今天是個不那么美好的一天。 但是學習不能停。 今天看教程講的是AJAX ASP/PHP的實例,但是我對PHP的掌握...
    迪迪醬OvO閱讀 544評論 0 1

友情鏈接更多精彩內(nèi)容