天天看點

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

[轉載] ubuntu下定制Vim/Gvim及使用技巧

vim是linux下的編輯器之神,是玩linux的必備工具,同樣emacs是神的編輯器,兩個編輯器是各有千秋,看個人的喜好,青菜蘿蔔各有所愛。我是比較喜歡vim,用vim編寫bash,perl,python腳本,以及修改配置檔案等等,本文就主要介紹在Ubuntu下gvim環境的搭建,希望對大家有所幫助。

一. Ubuntu安裝gvim方法

安裝gvim的方法,最簡單方法是在Ubuntu軟體中心搜尋gvim,然後點選安裝即可,如下圖:

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

如果使用指令行可以打開終端,輸入sudo apt-get install vim-gtk vim-doc cscope

二. 安裝gvim常用插件

    安裝好gvim後就可以使用了,不過在用gvim編寫代碼的時候還是有點小不友善,比如代碼的顔色高亮,自動補全,自動添加相關函數注釋,工程管理等等。這些都不必擔憂,gvim有很多的插件可以滿足上面的功能,甚至更多,下面我安裝的是我常用的一些插件。

Gvim插件可以到下面的網址自行選擇喜歡的插件: http://www.vim.org/scripts/script_search_results.php?order_by=downloads

taglist.vim插件:該插件是檢視源代碼的結構等,支援C/C++,java,php等多種語言。

安裝方法:

下載下傳taglist.zip,解壓到$HOME/.vim目錄中;

進入$home/.vim/doc目錄下,運作vim,輸入:help tags,啟用taglist的幫助文檔;

重新開機gvim,運作:TlistToggle啟用taglist

具體步驟:

 建立$HOME/.vim目錄

  1. -pc:~$ mkdir .vim 
下載下傳并解壓到.vim目錄中      
  1. -pc:~$ cd .vim/ 
  2. -pc:~/.vim$ unzip /home/test/下載下傳/taglist_45.zip 
  3. Archive: /home/test/下載下傳/taglist_45.zip 
  4. inflating: plugin/taglist.vim 
  5. inflating: doc/taglist.txt 

進入到doc目錄,并運作vim

  1. -pc:~/.vim$ cd doc/ 
  2. -pc:~/.vim/doc$ vim  
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

supertab插件:

安裝步驟:

1. 下載下傳該插件,下載下傳位址:

http://www.vim.org/scripts/script.php?script_id=1643

2.用vim打開supertab.vba檔案,并使之生效:so %,如圖:

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

perl-support.vim插件:

安裝方法:

下載下傳插件,下載下傳位址:

http://www.vim.org/scripts/script.php?script_id=556

将perl-support.zip解壓到$HOME/.vim目錄下

  1. -pc:~/.vim$ unzip /home/linuxpc/下載下傳/perl-support.zip 
  2. Archive: /home/linuxpc/下載下傳/perl-support.zip 
  3. inflating: doc/perlsupport.txt 
  4. inflating: README.perlsupport 
  5. creating: ftplugin/ 
  6. inflating: ftplugin/pod.vim 
  7. inflating: ftplugin/perl.vim 
  8. creating: autoload/ 
  9. inflating: autoload/perlsupportregex.vim 
  10. inflating: autoload/perlsupportgui.vim 
  11. inflating: autoload/perlsupportprofiling.vim 
  12. inflating: plugin/perl-support.vim 
  13. creating: perl-support/ 
  14. creating: perl-support/modules/ 
  15. inflating: perl-support/modules/perl-modules.list 
  16. creating: perl-support/templates/ 
  17. inflating: perl-support/templates/Templates 
  18. inflating: perl-support/templates/idioms.template  
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

bash-support.vim插件

與perl-support類似的一款插件,bash-support.vim插件,這兩個插件的功能類似

安裝步驟:

下載下傳插件,并解壓到$HOME/.vim目錄中

下載下傳位址:

  1. http://www.vim.org/scripts/download_script.php?src_id=17122

解壓到目錄下:

  1. -pc:~/.vim$ unzip /home/waydeechen/下載下傳/bash-support.zip 
  2. Archive: /home/waydeechen/下載下傳/bash-support.zip 
  3. inflating: README.bashsupport 
  4. inflating: doc/bashsupport.txt 
  5. inflating: ftplugin/sh.vim 
  6. creating: bash-support/ 
  7. creating: bash-support/templates/ 
  8. inflating: bash-support/templates/Templates 
  9. inflating: bash-support/templates/bash.paramsub.template 
  10. inflating: bash-support/templates/bash.statements.template 
  11. inflating: bash-support/templates/bash.comments.template 
  12. creating: bash-support/codesnippets/ 
  13. inflating: bash-support/codesnippets/timestamp  
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧
[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

AutoComplPop插件

AutoComplPop可以打開自動補全的視窗,不單單可以補全變量函數等,還可以補全檔案名。

下載下傳位址:http://www.vim.org/scripts/script.php?script_id=1879

安裝方法很簡單,将下載下傳的檔案解壓到$HOME/.vim目錄中

使用效果圖:

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

最後曬下自己的.vimrc檔案:

  1. set backspace=indent,eol,start 
  2. set history=50 " keep 50 lines of command line history 
  3. set ruler " show the cursor position all the time 
  4. set showcmd " display incomplete commands 
  5. set incsearch " do incremental searching 
  6. set number 
  7. syntax on “打開文法高亮 
  8. set autoindent “自動縮進 
  9. set smartindent “使用c形式自動縮進 
  10. set cindent 
  11. set tabstop=4 “TAB鍵的寬度 
  12. set shiftwidth=4 “統一縮進為4 
  13. set showmatch “高亮顯示比對括号 
  14. set incsearch 
  15. set nu “顯示行号 
  16. color darkblue ”顔色方案 
  17. set ruler 
  18. set ignorecase “搜尋忽略大小寫 
  19. set smartcase 
  20. set hlsearch ”設定搜尋字元高亮 
  21. set report=0 
  22. set mouse=a 
  23. set nobackup 
  24. set noeb 
  25. set history=1000 
  26. set nobackup 
  27. set noswapfile 
  28. set enc=utf-8 ”語言編碼設定 
  29. set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 
  30. set langmenu=ZH_CN.UTF-8 
  31. set helplang=cn 
  32. set laststatus=2 
  33. set ruler “顯示光标位置狀态行 
  34. set cmdheight=1 ”設定指令行的高度 
  35. filetype on “偵測檔案類型 
  36. filetype plugin on ”載入檔案類型插件 
  37. filetype indent on 
  38. set viminfo+=! “儲存全局變量 
  39. set iskeyword+=_,$,@,%,#,- ”帶有這些字元的單詞不要被換行分割 
  40. set linespace=0 “字元間插入像素行數目 
  41. set wildmenu ”指令行自動完成操作 
  42. set backspace=2 “使用回格鍵 
  43. set whichwrap+=<,>,h,l ”允許backspace和光标跨越行 
  44. set selection=exclusive 
  45. set selectmode=mouse,key 

vim常用使用方法:

:e:打開檔案,例::e /opt/shell/status.sh      

ZZ: 關閉檔案

vim +18 /opt/status.sh :打開status.sh并跳到第18行 

  1. vim +18 /opt/status.sh :打開status.sh并跳到第18行 
  2. 13 
  3. 14 ########## DEFINE FUNCTIONS ########## 
  4. 15 
  5. 16 function in_range_random_number() 
  6. 17 { 
  7. 18 #create a random number which is less than or equal to UPPER_LIMIT 
  8. 19 RANDOM_NUMBER=$(( $RANDOM % $UPPER_LIMIT + 1 )) 
  9. 20 echo -e "$RANDOM_NUMBER" 
  10. 21 } 
  1. 14 ########## DEFINE FUNCTIONS ########## 
  2. 15 
  3. 16 function in_range_random_number() 
  4. 17 { 
  5. 18 #create a random number which is less than or equal to UPPER_LIMIT 
  6. 19 RANDOM_NUMBER=$(( $RANDOM % $UPPER_LIMIT + 1 )) 
  7. 20 echo -e "$RANDOM_NUMBER" 
  8. 21 } 
  9. 22 

vim +/RANDOM_NUMBER /opt/shell/random_passwd_create.sh:打開腳本并從頭開始查詢,到第一個比對模式的地方

vim +?RANDOM_NUMBER /opt/shell/random_passwd_create.sh 從檔案尾搜尋

  1. vim +/^# /opt/shell/random_passwd_create.sh 
  2. 160 
  3. 161 ########## start of main ########## 
  4. 162 
  5. 163 trap `trap_exit;exit 2` 1 2 3 15 
  6. 164 
  7. 165 check_for_and_create_keyboard_file  

7. 将檔案部分寫入另一個檔案

  1. :5,15w /tmp/hshhs 

8. 删除空行

  1. :g/^$/d 

9. vimdiff 指令

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

10.vimgrep指令

[轉載] ubuntu下定制Vim/Gvim及使用技巧 [轉載] ubuntu下定制Vim/Gvim及使用技巧

更多Ubuntu相關資訊見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

posted @ 2016-01-25 16:56 Zander.Hu 閱讀( ...) 評論( ...) 編輯 收藏