Vim 編輯多個文件
在上一篇的文章中,我們介紹了在 Vim 中窗口分割同一文件,今天學習一下 Vim 編輯多個文件。
語法 : vim <file1> <file2> …
其中 file 不必是當前目錄的文件,你可以使用相對路徑或者絕對路徑下的 file 。在寫路徑的過程中,可以使用 Tab 來補全。
例如 , Vim 同時編輯當前目錄下的 hello.groovy helloWolrd 文件以及 當前用戶根目錄的 ~/hi-cat/log/hi-cat.log 文件。
$ vim hello.groovy helloWolrd ~/hi-cat/log/hi-cat.log
進入 Vim 中,默認打開的是第一個文件,即 hello.groovy , 此時如果想顯示文件列表可以在底行模式下輸入 ls :
:ls
顯示如下:
:ls
1 %a "hello.groovy" line 2
2 "helloWolrd" line 0
3 "hi-cat/log/hi-cat.log" line 0
此時可以通過以下命令,切換文件:
命令 | 作用 |
---|---|
:bp / :n | 上一個文件 |
:bn / :N | 下一個文件 |
:b[number] | number 爲 ls 命令顯示的文件前的數字 |
:b <fileName> | :b helloWolrd 可以使用 Tab 補全 |
如果你已經在 Vim 中打開了兩個文件,現在想要打開第三個文件 :
$ vim hello.groovy helloWolrd
此時在 Vim 中打開第三個文件:
:e ~/hi-cat/log/hi-cat.log
顯示當前文件列表
:ls