Vim多檔作業操作技

Vim split and tab

Vim作為一個Command line的文件編輯器,功能強大就眾所周知,不少開發者都愛用它來寫程式和操作系統文木檔,而寫程式往往需要編輯大量檔案,也需要開啟不同的檔案文件交互參照,但我們總不能開著一大堆視窗逐個切換吧?所以要用Vim寫程式,就不得不知如何應付多個檔案。

Vim不用另加插件,就支援多檔作業,當中最重要的就是視窗分割(Split Windows)、分頁(Tab Pages)和會話(Session)。學懂它們就能令Vim如IDE或其他圖形介面的進階文字編輯器一樣方便好用,以下就是這些功能的相關常用指令:

(為方便起見以下用英文)

Split Windows:

Function Command mode Normal mode
Horizontal split :sp[lit] {file} Ctrl-w + s
Vertical split :vs[plit] {file} Ctrl-w + v
Close current window :q/ :wq Ctrl-w + c
Close all other windows Ctrl-w + o
Switch split window Ctrl-w + Ctrl-w/W
Ctrl-w + arrow / h/j/k/l
Resize split window Ctrl-w + {n} + (+/-) (row)
Ctrl-w + {n} + </> (column)
Move split window to an edge and maximize Ctrl-w + H/J/K/L
Rotate split windows’ order Ctrl-w + r/R

Tab page:

Function Command mode Normal mode
Create tab :{n}tabe[dit] {file}
n: open after nth tab
Close current tab :tabc[lose]
Close all other tabs :tabo[nly]
Switch tab :tabn[ext] (next)
:tabN {n} (next n tabs)
:tabp[revious] (previous)
:tabfir[st] (first)
:tabr[wind](first)
:tabl[ast] (last)
gt (next)
gT (previous)
{n}gt (to nth tab)
Move tab :tabm[ove] {n}
n: move to after nth tab
List tabs and files :tabs

Session:

Save current session: :mks[!] {session_file_path}

Load session file: :source {session_file_path}

以上[xxx]為選擇性輸入,{n}為參數

另附短片:

以上指令只是一些個人認為比較方便的操作方法,事實上同一個操作有更多不同的輸入方式,亦有更多操作指令可用。詳情可讀Vim官方說明文件:

廣告

Vim多檔作業操作技 有 “ 1 則留言 ”

  1. 引用通告: My Tiny Vim Configuration v0.3.0 « 青鳥脈博

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s