1. 程式人生 > >Ubuntu下的C/C++環境搭建

Ubuntu下的C/C++環境搭建

以下是滇狐收集和整理的一些有用的 VIM 外掛, 大部分外掛都有自己詳細的說明書,因此這裡就不詳細介紹每個外掛的安裝和使用方法了。 通過這些外掛, VIM 能夠變成一個非常強大的平臺, Happy VIMming! 如果想詳細瞭解預設的外掛外掛安裝路徑,請看這裡

1 程式設計

1.1 Tag List

下載地址: 官方站點

官方描述: The “Tag List” plugin is a source code browser plugin for Vim and provides an overview of the structure of source code files and allows you to efficiently browse through source code files for different programming languages.

滇狐評價: 這是一個非常非常非常非常重要的外掛, 有了它, 我們才能夠在 VIM 中檢視一個檔案中包含的函式列表, 或是一個類包含的方法列表, 為程式設計人員提供了極大方便。推薦大家一定要安裝!

安裝注意事項: 有的系統內建的 ctags 功能太弱, 推薦大家安裝 , 這個東西功能比較強大, 居然連 HTML 裡面內嵌的 Java Script 都能夠支援, 實在是匪疑所思!

滇狐個人習慣: 滇狐習慣把方法列表放在螢幕的右側, 於是在 .vimrc 中設定了

								
										let
								 Tlist_Use_Right_Window=
1

另外, 滇狐習慣讓當前不被編輯的檔案的方法列表自動摺疊起來, 這樣可以節約一些螢幕空間,於是在 .vimrc 中設定了

								
										let
								 Tlist_File_Fold_Auto_Close=1

1.2 A

下載地址: 官方站點

官方描述:

A few of quick commands to swtich between source files and header files quickly.

:A switches to the header file corresponding to the current file being edited (or vise versa)

:AS splits and switches

:AV vertical splits and switches

E.g. if you are editing foo.c and need to edit foo.h simply execute :A and you will be editting foo.h, to switch back to foo.c execute :A again.

滇狐評價: 第一眼看到這個東西時, 總覺得它功能太簡單, 似乎沒有什麼用處。用過之後, 才發現這項功能對於一個程式設計師來說是如何重要!

1.3 Win Manager

下載地址: 官方站點

官方描述: winmanager is a plugin which implements a classical windows type IDE in Vim-6.0. Basically, you have the directory tree and the buffer list as 2 windows which stay on the left and the editing is done in a seperate area on the left. People have already made excellent File and Buffer explorers seperately and I thought that it might be a cool idea to combine them both. winmanager.vim combines the standard File Explorer which ships with Vim 6.0 and a Buffer Explorer written by Jeff Lanzarotta into one package.

滇狐評價: 非常好用的東西, 在螢幕上開啟一個檔案瀏覽器, 這樣就可以方便地選擇要編輯的檔案了。

預設情況下, winmanager 依賴於 bufexplorer,到這裡下載。如果你不喜歡 bufexplorer 外掛的話 可以在你的 .vimrc 中新增這條命令禁用它:

								
										let
								 g:winManagerWindowLayout ="FileExplorer"

這樣就不需要下載該外掛了。

滇狐為 winfileexplorer.vim 加了一個補丁, 提供了使用系統預設開啟方式開啟選中檔案的功能,只要把游標放在想要開啟的檔案上, 然後按“S”就可以了 (注意是大寫)。這樣以後就可以直接在 gvim 裡開啟 xmms, 不用再切換出來找 konqueror 了。

1.4 gdbvim

下載地址: 官方站點

官方描述: You have one window with (g)vim open, other window with gdb running. When you reach source line in your code, it appears in the vim window. In the opposite direction, you can send commands from vim to gdb (e.g., set breakpoints on given line).

滇狐評價: 該外掛意義很重大, 為我們在 VIM 中除錯程式提供了可能。 雖然功能還非常少,但已經足以解決平常的大部分需求了。 原始版本問題比較多, 例如只能新增斷點,不能刪除斷點, 滇狐為該外掛添加了刪除已加斷點的功能。 另外快捷鍵的設定也比較不快捷,滇狐又順便把相應的快捷鍵修改了一下, 現在用起來已經比較順暢了, 放出來給大家參觀一下,以便繼續改進。 目前只在 Linux 下除錯通過, 其它平臺未經測試, 感興趣的朋友可以在其它平臺下測試,並彙報測試結果。

需要繼續增加的功能: 下一步滇狐準備再給這個外掛加上儲存所有斷點的功能,這樣下次除錯的時候就不用重新設定斷點了。 另外, 目前檢視變數的值時,只能把結果列印到 console 視窗中, 滇狐希望在下一個版本中能夠把檢視結果抓取到 VIM 中顯示。 VIM 網站上給出了把所有結果抓取到 VIM 中的實現, 但那不是滇狐希望的結果。滇狐最希望得到的結果是使用 tooltip 顯示變數結果, 另外能夠再提供一個 watch 視窗, 時刻監視變數的值, 以後慢慢實現吧。

安裝注意事項: gdbvim 指令碼是使用 Perl 語言編寫的, 因此需要安裝 Perl。為了方便你的使用, 建議在 $PATH 路徑下新增一個指向 plugin/gdbvim 指令碼的符號連結, 或者直接將該檔案複製到 $PATH 路徑下,滇狐推薦前者。 還有, 最好在你的 .vimrc 中 set noshowcmd,否則大量的“請按 ENTER 繼續”會把你活活煩死。 另外, 滇狐 patch 過的指令碼依賴 ,如果你使用滇狐版的話, 需要再安裝這個外掛。

使用方法: 編譯你的程式時加上 -g 引數生成除錯資訊, 然後使用“gdbvim <你的程式名>”啟動 gdbvim, gdbvim 會自動啟動一個 gvim。 將 gvim 最大化, 然後就可以使用 Gdb 選單或快捷鍵新增斷點、 單步除錯程式、 檢視變數值了。

1.5 jad

下載地址: 無。 自己將程式碼複製貼上回去, 儲存為 $HOME/.vim/plugins/jad.vim:

								
										augr
								 class
au!
aubufreadpost,filereadpost *.class %!jad -noctor -ff -i -p %aubufreadpost,filereadpost *.class setreadonlyaubufreadpost,filereadpost *.class setft=java
aubufreadpost,filereadpost *.class normal gg=G
aubufreadpost,filereadpost *.class setnomodifiedaubufreadpost,filereadpost *.class setnomodifiableaugr END

官方描述: (無)

滇狐評價: 挺好玩的外掛, 不過似乎也只是好玩而已。 安裝了之後可以直接雙擊開啟 .class 檔案, VIM 會自動呼叫 jad 把檔案反編譯了。

安裝注意事項:需要先安裝一份 jad

1.6 cscope_maps

下載地址: 官方站點

官方描述: Cscope is a very handy tool, but it’s even better when you don’t ever have to leave the comfort of your favorite editor (i.e. Vim) to use it. Fortunately, Cscope support has been built into Vim.

滇狐評價: 滇狐目前 cscope 用得不如 ctags 多, 許多功能都不大熟。 不過既然大家都說好,那還是裝著玩玩吧。

安裝注意事項: 需要安裝 。

1.7 project

下載地址: 官方站點

官方描述: You can use this plugin’s basic functionality to set up a list of frequently-accessed files for easy navigation. The list of files will be displayed in a window on the left side of the Vim window, and you can press <Return> or double-click on filenames in the list to open the files. This is similar to how some IDEs I’ve used work. I find this easier to use than having to navigate a directory hierarchy with the file-explorer. It also obviates the need for a buffer explorer because you have your list of files on the left of the Vim Window.

滇狐評價: 食之無肉,棄之有味。

安裝注意事項: 幾乎沒怎麼用過, 所以暫時沒有發現需要注意的地方。

2 文件編寫

2.1 VIM LaTeX Suite

下載地址: 官方站點

官方描述:

Vim is undoubtedly one of the best editors ever made. LaTeX is an extremely powerful, intelligent typesetter. Vim-LaTeX aims at bringing together the best of both these worlds.

We attempt to provide a comprehensive set of tools to view, edit and compile LaTeX documents without needing to ever quit Vim. Together, they provide tools starting from macros to speed up editing LaTeX documents to compiling tex files to forward searching .dvi documents.

See the features page for a brief tour of the various features in LaTeX-suite. All these features can be tuned extensively using the included texrc file. The screenshots page shows you how a typical working session with LaTeX-suite might progress.

LaTeX-suite is made for Vim versions 6.0 and above. Installation instructions are given in the download page.

滇狐評價: 實在是非常非常非常非常好的一個外掛! 用 VIM 寫 LaTeX 的朋友無論如何都要試一試,不用 VIM 寫 LaTeX 的朋友也要試一試, 說不定你會改變你的主意, 改用 VIM 寫 LaTeX。

安裝注意事項: 如果使用 gvim 的話, 需要注意 scim 可能會和 LaTeX Suite 有衝突。 解決方法是要麼把 scim 的 on the spot 功能去掉, 或者把 gtk_im_module 設為 scim。 (較新版本 scim 建議第二種方案)。

另外, 為了提高工作效率, 強烈建議配置 VIM 的LaTeX 正向、反向搜尋功能。

2.2 sketch

下載地址: 官方站點

官方描述: Sketch.vim – Line drawing/painting using the mouse. Based on an idea by Morris.

滇狐評價: 很好玩, 雖然用到的時候不多, 但真一旦用到了, 還是會覺得這個東西很有用的。

安裝注意事項: 建議在 .vimrc 中把 call ToggleSketch() 對映為命令,方便一些:

								
										command
								
								
										-
								
								nargs
								
										=
								
								
										0
								 ToggleSketch call ToggleSketch()

3 日常生活

3.1 Calendar

下載地址: 官方站點

官方描述: This script create calender window. This don’t use the external program (cal).

滇狐評價: 安裝完畢後使用 :Calendar 命令開啟一個垂直的日曆視窗, 使用 :CalendarH 命令開啟水平的日曆視窗。 應該還是比較有用的。

安裝注意事項: 滇狐個人喜歡把日記的副檔名改成 .txt, 預設的是 .cal。在 calendar.vim 裡面查詢替換一下就可以了。 另外, 可以在 .vimrc 裡面修改日記所在的路徑,預設是 ~/diary。

								
										let
								 g:calendar_diary=<PATH>

3.2 vimtips

下載地址: 官方站點

官方描述:

Whenever you start Vim (but no more than daily) the script will open a help window with a Vim tip. You must download the tips separately, from 官方站點

After installation, you can get the next tip with

:TipOfTheDay

滇狐評價: 每天看一條,慢慢就變成 VIM 牛了。

安裝注意事項: 暫時沒發現。

3.3 ViKi

你現在看到的這張網頁就是使用 ViKi 製作的。 也許它不漂亮, 但是很清秀, 而且新增資訊非常方便。 是 ViKi 將滇狐從繁重的 Html 編輯工作中解放出來, 使滇狐有足夠的勇氣重新開始製作個人主頁。 為了更好地說明 ViKi,滇狐將該外掛的使用單獨放到另一張網頁中。