自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

5個好用的開發(fā)者Vim插件

開發(fā) 開發(fā)工具
我用 Vim 已經(jīng)超過 20 年了,兩年前我決定把它作為我的首要文本編輯器。我用 Vim 來編寫代碼、配置文件、博客文章及其它任意可以用純文本表達的東西。Vim 有很多超級棒的功能,一旦你適合了它,你的工作會變得非常高效。

 [[258120]]

通過這 5 個插件擴展 Vim 功能來提升你的編碼效率。

我用 Vim 已經(jīng)超過 20 年了,兩年前我決定把它作為我的首要文本編輯器。我用 Vim 來編寫代碼、配置文件、博客文章及其它任意可以用純文本表達的東西。Vim 有很多超級棒的功能,一旦你適合了它,你的工作會變得非常高效。

在日常編輯工作中,我更傾向于使用 Vim 穩(wěn)定的原生功能,但開源社區(qū)對 Vim 開發(fā)了大量的插件,可以擴展 Vim 的功能、改進你的工作流程和提升工作效率。

以下列舉 5 個非常好用的可以用于編寫任意編程語言的插件。

1、Auto Pairs

Auto Pairs 插件可以幫助你插入和刪除成對的文字,如花括號、圓括號或引號。這在編寫代碼時非常有用,因為很多編程語言都有成對標(biāo)記的語法,就像圓括號用于函數(shù)調(diào)用,或引號用于字符串定義。

Auto Pairs 最基本的功能是在你輸入一個左括號時會自動補全對應(yīng)的另一半括號。比如,你輸入了一個 [,它會自動幫你補充另一半 ]。相反,如果你用退格鍵刪除開頭的一半括號,Auto Pairs 會刪除另一半。

如果你設(shè)置了自動縮進,當(dāng)你按下回車鍵時 Auto Pairs 會在恰當(dāng)?shù)目s進位置補全另一半括號,這比你找到放置另一半的位置并選擇一個正確的括號要省勁多了。

例如下面這段代碼:

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. x := true
  7. items := []string{"tv", "pc", "tablet"}
  8.  
  9. if x {
  10. for _, i := range items
  11. }
  12. }

items 后面輸入一個左花括號按下回車會產(chǎn)生下面的結(jié)果:

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. x := true
  7. items := []string{"tv", "pc", "tablet"}
  8.  
  9. if x {
  10. for _, i := range items {
  11. | (cursor here)
  12. }
  13. }
  14. }

Auto Pairs 提供了大量其它選項(你可以在 GitHub 上找到),但最基本的功能已經(jīng)很讓人省時間了。

2、NERD Commenter

NERD Commenter 插件給 Vim 增加了代碼注釋的功能,類似在 IDEintegrated development environment 中注釋功能。有了這個插件,你可以一鍵注釋單行或多行代碼。

NERD Commenter 可以與標(biāo)準(zhǔn)的 Vim filetype 插件配合,所以它能理解一些編程語言并使用合適的方式來注釋代碼。

最易上手的方法是按 Leader+Space 組合鍵來切換注釋當(dāng)前行。Vim 默認的 Leader 鍵是 \

可視化模式Visual mode中,你可以選擇多行一并注釋。NERD Commenter 也可以按計數(shù)注釋,所以你可以加個數(shù)量 n 來注釋 n 行。

還有個有用的特性 “Sexy Comment” 可以用 Leader+cs 來觸發(fā),它的塊注釋風(fēng)格更漂亮一些。例如下面這段代碼:

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. x := true
  7. items := []string{"tv", "pc", "tablet"}
  8.  
  9. if x {
  10. for _, i := range items {
  11. fmt.Println(i)
  12. }
  13. }
  14. }

選擇 main 函數(shù)中的所有行然后按下 Leader+cs 會出來以下注釋效果:

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. /*
  7. * x := true
  8. * items := []string{"tv", "pc", "tablet"}
  9. *
  10. * if x {
  11. * for _, i := range items {
  12. * fmt.Println(i)
  13. * }
  14. * }
  15. */
  16. }

因為這些行都是在一個塊中注釋的,你可以用 Leader+Space 組合鍵一次去掉這里所有的注釋。

NERD Commenter 是任何使用 Vim 寫代碼的開發(fā)者都必裝的插件。

3、VIM Surround

Vim Surround 插件可以幫你“環(huán)繞”現(xiàn)有文本插入成對的符號(如括號或雙引號)或標(biāo)簽(如 HTML 或 XML 標(biāo)簽)。它和 Auto Pairs 有點兒類似,但是用于處理已有文本,在編輯文本時更有用。

比如你有以下一個句子:

  1. "Vim plugins are awesome !"

當(dāng)你的光標(biāo)處于引起來的句中任何位置時,你可以用 ds" 組合鍵刪除句子兩端的雙引號。

  1. Vim plugins are awesome !

你也可以用 cs"' 把雙端的雙引號換成單引號:

  1. 'Vim plugins are awesome !'

或者再用 cs'[ 替換成中括號:

  1. [ Vim plugins are awesome ! ]

它對編輯 HTML 或 XML 文本中的標(biāo)簽tag尤其在行。假如你有以下一行 HTML 代碼:

  1. <p>Vim plugins are awesome !</p>

當(dāng)光標(biāo)在 “awesome” 這個單詞的任何位置時,你可以按 ysiw<em> 直接給它加上著重標(biāo)簽(<em>):

  1. <p>Vim plugins are <em>awesome</em> !</p>

注意它聰明地加上了 </em> 閉合標(biāo)簽。

Vim Surround 也可以用 ySS 縮進文本并加上標(biāo)簽。比如你有以下文本:

  1. <p>Vim plugins are <em>awesome</em> !</p>

你可以用 ySS<div class="normal"> 加上 div 標(biāo)簽,注意生成的段落是自動縮進的。

  1. <div class="normal">
  2.         <p>Vim plugins are <em>awesome</em> !</p>
  3. </div>

Vim Surround 有很多其它選項,你可以參照 GitHub 上的說明嘗試它們。

4、Vim Gitgutter

Vim Gitgutter 插件對使用 Git 作為版本控制工具的人來說非常有用。它會在 Vim 的行號列旁顯示 git diff 的差異標(biāo)記。假設(shè)你有如下已提交過的代碼:

  1.   1 package main
  2.   2
  3.   3 import "fmt"
  4.   4
  5.   5 func main() {
  6.   6     x := true
  7.   7     items := []string{"tv", "pc", "tablet"}
  8.   8
  9.   9     if x {
  10.  10         for _, i := range items {
  11.  11             fmt.Println(i)
  12.  12         }
  13.  13     }
  14.  14 }

當(dāng)你做出一些修改后,Vim Gitgutter 會顯示如下標(biāo)記:

  1.     1 package main
  2.     2
  3.     3 import "fmt"
  4.     4
  5. _   5 func main() {
  6.     6     items := []string{"tv", "pc", "tablet"}
  7.     7
  8. ~   8     if len(items) > 0 {
  9.     9         for _, i := range items {
  10.    10             fmt.Println(i)
  11. +  11             fmt.Println("------")
  12.    12         }
  13.    13     }
  14.    14 }

_ 標(biāo)記表示在第 5 行和第 6 行之間刪除了一行。~ 表示第 8 行有修改,+ 表示新增了第 11 行。

另外,Vim Gitgutter 允許你用 [c]c 在多個有修改的塊之間跳轉(zhuǎn),甚至可以用 Leader+hs 來暫存某個變更集。

這個插件提供了對變更的即時視覺反饋,如果你用 Git 的話,有了它簡直是如虎添翼。

5、VIM Fugitive

Vim Fugitive 是另一個將 Git 工作流集成到 Vim 中的超棒插件。它對 Git 做了一些封裝,可以讓你在 Vim 里直接執(zhí)行 Git 命令并將結(jié)果集成在 Vim 界面里。這個插件有超多的特性,更多信息請訪問它的 GitHub 項目頁面。

這里有一個使用 Vim Fugitive 的基礎(chǔ) Git 工作流示例。設(shè)想我們已經(jīng)對下面的 Go 代碼做出修改,你可以用 :Gblame 調(diào)用 git blame 來查看每行***的提交信息:

  1. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    1 package main
  2. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    2
  3. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    3 import "fmt"
  4. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    4
  5. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│_   5 func main() {
  6. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    6     items := []string{"tv", "pc", "tablet"}
  7. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    7
  8. 00000000 (Not Committed Yet 2018-12-05 18:55:00 -0500)│~   8     if len(items) > 0 {
  9. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│    9         for _, i := range items {
  10. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│   10             fmt.Println(i)
  11. 00000000 (Not Committed Yet 2018-12-05 18:55:00 -0500)│+  11             fmt.Println("------")
  12. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│   12         }
  13. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│   13     }
  14. e9949066 (Ricardo Gerardi   2018-12-05 18:17:19 -0500)│   14 }

可以看到第 8 行和第 11 行顯示還未提交。用 :Gstatus 命令檢查倉庫當(dāng)前的狀態(tài):

  1.   1 # On branch master
  2.   2 # Your branch is up to date with 'origin/master'.
  3.   3 #
  4.   4 # Changes not staged for commit:
  5.   5 #   (use "git add <file>..." to update what will be committed)
  6.   6 #   (use "git checkout -- <file>..." to discard changes in working directory)
  7.   7 #
  8.   8 #       modified:   vim-5plugins/examples/test1.go
  9.   9 #
  10.  10 no changes added to commit (use "git add" and/or "git commit -a")
  11. --------------------------------------------------------------------------------------------------------
  12.     1 package main
  13.     2
  14.     3 import "fmt"
  15.     4
  16. _   5 func main() {
  17.     6     items := []string{"tv", "pc", "tablet"}
  18.     7
  19. ~   8     if len(items) > 0 {
  20.     9         for _, i := range items {
  21.    10             fmt.Println(i)
  22. +  11             fmt.Println("------")
  23.    12         }
  24.    13     }
  25.    14 }

Vim Fugitive 在分割的窗口里顯示 git status 的輸出結(jié)果。你可以在該行按下 - 鍵用該文件的名字暫存這個文件的提交,再按一次 - 可以取消暫存。這個信息會隨著你的操作自動更新:

  1.   1 # On branch master
  2.   2 # Your branch is up to date with 'origin/master'.
  3.   3 #
  4.   4 # Changes to be committed:
  5.   5 #   (use "git reset HEAD <file>..." to unstage)
  6.   6 #
  7.   7 #       modified:   vim-5plugins/examples/test1.go
  8.   8 #
  9. --------------------------------------------------------------------------------------------------------
  10.     1 package main
  11.     2
  12.     3 import "fmt"
  13.     4
  14. _   5 func main() {
  15.     6     items := []string{"tv", "pc", "tablet"}
  16.     7
  17. ~   8     if len(items) > 0 {
  18.     9         for _, i := range items {
  19.    10             fmt.Println(i)
  20. +  11             fmt.Println("------")
  21.    12         }
  22.    13     }
  23.    14 }

現(xiàn)在你可以用 :Gcommit 來提交修改了。Vim Fugitive 會打開另一個分割窗口讓你輸入提交信息:

  1.   1 vim-5plugins: Updated test1.go example file
  2.   2 # Please enter the commit message for your changes. Lines starting
  3.   3 # with '#' will be ignored, and an empty message aborts the commit.
  4.   4 #
  5.   5 # On branch master
  6.   6 # Your branch is up to date with 'origin/master'.
  7.   7 #
  8.   8 # Changes to be committed:
  9.   9 #       modified:   vim-5plugins/examples/test1.go
  10.  10 #

:wq 保存文件完成提交:

  1. [master c3bf80f] vim-5plugins: Updated test1.go example file
  2.  1 file changed, 2 insertions(+), 2 deletions(-)
  3. Press ENTER or type command to continue

然后你可以再用 :Gstatus 檢查結(jié)果并用 :Gpush 把新的提交推送到遠程。

  1.   1 # On branch master
  2.   2 # Your branch is ahead of 'origin/master' by 1 commit.
  3.   3 #   (use "git push" to publish your local commits)
  4.   4 #
  5.   5 nothing to commit, working tree clean

Vim Fugitive 的 GitHub 項目主頁有很多屏幕錄像展示了它的更多功能和工作流,如果你喜歡它并想多學(xué)一些,快去看看吧。

接下來?

這些 Vim 插件都是程序開發(fā)者的神器!還有另外兩類開發(fā)者常用的插件:自動完成插件和語法檢查插件。它些大都是和具體的編程語言相關(guān)的,以后我會在一些文章中介紹它們。

你在寫代碼時是否用到一些其它 Vim 插件?請在評論區(qū)留言分享。

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2016-10-31 15:27:23

Vim

2017-04-05 15:00:26

VimLinux開源

2016-10-31 15:13:56

Vim

2016-10-27 13:07:39

Vim插件開發(fā)者

2015-03-10 09:23:21

前端開發(fā)Sublime插件Sublime

2024-01-26 06:25:09

PyCharm插件代碼

2022-06-29 08:59:46

Java插件開發(fā)

2011-10-31 15:08:54

Chrome插件Web設(shè)計開發(fā)

2012-08-20 09:57:15

新興平臺汽車智能家電

2019-08-27 09:08:52

后端隊列系統(tǒng)

2024-01-09 18:03:30

開發(fā)者插件代碼

2024-11-04 18:32:20

2012-06-13 01:23:30

開發(fā)者程序員

2010-09-02 13:32:52

jQueryjQuery插件

2015-09-06 16:22:48

JavaScriptSublimeText

2013-07-23 15:28:38

開發(fā)者Eclipse插件

2013-12-27 09:03:47

開發(fā)項目

2012-09-19 10:25:56

iPhone 5游戲開發(fā)者

2015-11-13 10:45:48

ASP.NET開發(fā)者

2015-06-04 13:15:11

獨立開發(fā)者
點贊
收藏

51CTO技術(shù)棧公眾號