vim 編輯器中的一款很強大外掛程式—— vim fugitive 。這款外掛程式可以實現你在 vim 編輯器裡直接完成 git 操作,而無需退出 vim 。
安裝方法:
cd ~/.vim/bundle
git clone .git
vim -u none -c "helptags vim-fugitive/doc" -c q複製**
現在進行一些基本功能演示。假如現在有這麼一段**:
1 package main
3 import "fmt"
5 func main()
9 if x
13 }
14 }複製**
現在我們將第 6 行刪除,再修改第 9 行,同時在 11 行後新增一行**。現在我們想檢視這些修改,按往常做法,我們是先儲存文件再退出,然後執行 git status 。
但現在,我們不必退出,直接在命令模式下輸入 :gstatus ,直接就可以看到改動:
1 # on branch master
2 # your branch is up to date with 'origin/master'.
3 #4 # changes not staged for commit:
5 # (use "git add ..." to update what will be committed)
6 # (use "git checkout -- ..." to discard changes in working directory)
7 #8 # modified: vim-5plugins/examples/test1.go
9 #10 no changes added to commit (use "git add" and/or "git commit -a")
1 package main
3 import "fmt"
_ 5 func main()
~ 8 if len(items) > 0
13 }
14 }複製**
如結果所示,vim fugitive 開啟了乙個有上下分屏的介面,上面一半,跟我們平常執行 git status 看到的結果一樣,下面一半,就是具體發動內容,跟 git diff 類似。
在下半屏裡,有三個符號:_ 表示在第 5 行與第 6 行之間有**被刪除,~ 表示在第 8 行**被修改過,+ 表示 11 行新增了**。
同樣的,我們可以檢視每行**是誰改的,可以用 git blame ,而在這裡對應的是 gblame 。
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 1 package main
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 2
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 3 import "fmt"
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 4
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│_ 5 func main()
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 7
00000000 (not committed yet 2019-6-7 18:55:00 -0500)│~ 8 if len(items) > 0
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 13 }
e9949066 (alvin yan 2019-6-7 18:17:19 -0500)│ 14 }複製**
我們同樣也看到第 8 和 11 行還沒有提交。
現在我們想要提交我們的改動,可以敲入 :gcommit 命令。vim fugitive 將開啟另外一塊區域,我們可以在裡面寫入要提交的資訊。
1 vim-5plugins: updated test1.go example file
2 # please enter the commit message for your changes. lines starting
3 # with '#' will be ignored, and an empty message aborts the commit.
4 #5 # on branch master
6 # your branch is up to date with 'origin/master'.
7 #8 # changes to be committed:
9 # modified: vim-5plugins/examples/test1.go
10 #複製**
然後我們就可以執行 :wq 結束提交。
[master c3bf80f] vim-5plugins: updated test1.go example file
1 file changed, 2 insertions(+), 2 deletions(-)
press enter or type command to continue複製**
我們同樣可以繼續使用 :gstatus 來檢視提交後的狀態,也可以使用 :gpush 將提交推送到遠端倉庫。
1 # on branch master
2 # your branch is ahead of 'origin/master' by 1 commit.
3 # (use "git push" to publish your local commits)
4 #5 nothing to commit, working tree clean複製**
以上這些是 vim fugitive 最基礎的用法,如果想學習它的更高階用法,可以去它的 github倉庫檢視,那裡有更詳細的教程。
VIM的高階用法
在vim的配置檔案 etc vimrc 中 syntax on 支援語法高亮 set nu 顯示行號 set nonu 不顯示行號 set ai 設定自動縮排 set shiftwidth 4 設定自動縮排 4 個空格,當然要設自動縮排先 set sts 4 即設定 softtabstop 為 4....
vim高階用法
瀏覽模式 只能對檔案內容進行瀏覽 插入模式 對檔案內容進行修改的模式 推出模式 結束vim程式使用到的指令 vimtutor vim使用手冊 命令開啟vim程式在程式中輸入help 在vim瀏覽模式中 set 設定 如 set nu 顯示行號 set nonu 取消顯示行號 set cursorli...
Vim高階用法
域功能 標識域為從游標位置開始到當前行尾 0標識域為從游標位置前到當前行首e或 w標識域為從游標位置開始到當前字尾 其他用法 如3dw,刪除游標後3個字 b標識域為從游標位置前到當前字首 5.緩衝區的使用 5.1 數字編號緩衝區 雙引號 n 緩衝區號,1至9 p或p 例如 9p 其中對數字緩衝區的使...