用GVim建立IDE編程環境(Win篇)

jopen 10年前發布 | 46K 次閱讀 GVim

說明:本文是作者在完全按照著名的《手把手教你把Vim改裝成一個IDE編程環境》一文,在WindowsXP上用gvim建立IDE環境時所作的備忘。

原作地址:http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx

0.準備軟件及插件。
(a)gvim72.exe

地址ftp://ftp.vim.org/pub/vim/pc/gvim72.exe
(b)vimcdoc-1.7.0-setup.exe

地址http://prdownloads.sourceforge.net/vimcdoc/vimcdoc-1.7.0-setup.exe?download
(c)ec57w32.zip

地址http://prdownloads.sourceforge.net/ctags/ec57w32.zip
(d)taglist_45.zip

地址http://www.vim.org/scripts/download_script.php?src_id=7701
(e)winmanager.zip

地址http://www.vim.org/scripts/download_script.php?src_id=754
(f)minibufexpl.vim

地址http://www.vim.org/scripts/download_script.php?src_id=3640
(g)a.vim

地址http://www.vim.org/scripts/download_script.php?src_id=7218
(h)grep.vim

地址http://www.vim.org/scripts/download_script.php?src_id=7645
(i)visualmark.vim

地址http://www.vim.org/scripts/download_script.php?src_id=4700

1、安裝Gvim7.3 : 下載地址http://www.vim.org/download.php#pc

2、安裝中文幫助:vimcdoc-1.8.0-setup.exe 地址http://vimcdoc.sourceforge.net/

      會自動識別gvim的安裝路徑,

      安裝完后,gvim菜單中文出現亂碼,在_vimrcset文件中增加:

" 配置多語言環境,解決中文亂碼問題

if has("multi_byte") 
    " UTF-8 編碼 
    set encoding=utf-8 
    set termencoding=utf-8 
    set formatoptions+=mM 
    set fencs=utf-8,gbk 
    if v:lang =~? '^/(zh/)/|/(ja/)/|/(ko/)' 
        set ambiwidth=double 
    endif 
    if has("win32") 
        source $VIMRUNTIME/delmenu.vim 
        source $VIMRUNTIME/menu.vim 
        language messages zh_CN.utf-8 
    endif 
else 
    echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" 
endif

     輸入:help,顯示中文幫助,說明安裝成功:

用GVim建立IDE編程環境(Win篇)

3、設置語法高亮

編輯安裝目錄下的_vimrc文件(例如:我的在D:\Program Files\Vim)

     加入以下內容:

     set nu!

     colorscheme desert 
     syntax enable 
     syntax on

再打開gvim,打開一個源代碼文件:

用GVim建立IDE編程環境(Win篇)

這些設置使得gvim可以顯示行號,并使用了desert配色方案,而且打開了語法高亮功能(用不同顏色顯示注釋、關鍵字、字符串等)。 
我們還可以讓函數名也高亮起來,

這里對C、C++的代碼進行配置:在D:\Program Files\Vim\vim73\syntax下找到 c.vim 和 cpp.vim,分別添加以下內容: 
syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2 
syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1 
hi cFunction gui=NONE guifg=#B5A1FF

重新打開gvim,效果如下:

用GVim建立IDE編程環境(Win篇)


4、程序中跳轉

將ec57w32.zip解壓,在解壓后將文件夾中的ctags.exe復制到D:\ProgramFiles\Vim\vim73下,并編輯_vimrc文件,添加以下內容: 
set tags=tags; 
set autochdir

 

然后將D:\ProgramFiles\Vim\vim73加到環境變量的path中。在需要查看的源代碼目錄下執行命令ctags -R;然后再用gvim打開源代碼文件:

用GVim建立IDE編程環境(Win篇)


按住“CTRL”鍵,點擊對應的函數名或“CTRL+]”,會自動跳轉到函數的定義部分,“CTRL+T”則返回;

5、源代碼分析工具 taglist

將taglist_45.zip解壓,解壓后包含一個doc文件夾和一個plugin文件夾,將其中內容分別復制到d:\Program Files\Vim\vim73下的doc及plugin中。 
在_vimrc文件中加入以下內容: 
let Tlist_Show_One_File=1 
let Tlist_Exit_OnlyWindow=1

用GVim建立IDE編程環境(Win篇)


用gvim打開代碼文件(已生成過tags文件),輸入:Tlist,TagList窗口即出現在左側。再輸入:

:Tlist,左側欄消失;左側欄列出了當前文件中的所有宏,  全局變量,  函數名等,  在查看代碼時用這個窗口總攬全局,  切換位置相當方便

用GVim建立IDE編程環境(Win篇)



6、文件瀏覽組件 WinManager

winmanager.zip 地址http://www.vim.org/scripts/download_script.php?src_id=754

將winmanager.zip解壓和拷貝,解壓后包含一個doc文件夾和一個plugin文件夾,將其中內容分別復制到d:\Program Files\Vim\vim73下的doc及plugin中

在_vimrc文件中加入以下內容:

let g:winManagerWindowLayout='FileExplorer|TagList' 
nmap wm :WMToggle

用gvim打開代碼文件,normal狀態下輸入命令"wm",窗口如下:

用GVim建立IDE編程環境(Win篇)

左上角是瀏覽文件的窗口,左下角的是TagList窗口;

7、多文檔編輯

minibufexpl.vim 地址http://www.vim.org/scripts/download_script.php?src_id=3640

解壓后將將minibufexpl.vim復制到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加:

let g:miniBufExplMapCTabSwitchBufs=1 
let g:miniBufExplMapWindowsNavVim=1 

let g:miniBufExplMapWindowNavArrows=1

let g:miniBufExplorerMoreThanOne=0

用GVIM打開多個源代碼文件后,如圖:

用GVim建立IDE編程環境(Win篇)

ctrl+Tab,切換到前一個buffer,并在當前窗口打開文件; 
ctrl+shift+Tab,切換到后一個buffer,并在當前窗口打開文件; 
ctrl+箭頭鍵,可以切換到上下左右窗口中; 
ctrl+h,j,k,l,切換到上下左右的窗口中。


8、在工程中快速查找

grep.vim 地址http://www.vim.org/scripts/download_script.php?src_id=7645

解壓后把grep.vim文件拷貝到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加:

nnoremap :Grep

因為windows下是不帶grep的,需要下載Grep for Windows http://gnuwin32.sourceforge.net/packages/grep.htm

下載后在環境變量中增加grep的路徑;

用gvim打開一個源代碼文件,光標選擇需要查找的內容,按F3,確定要查找的內容和搜索范圍,gvim會在彈出的QuickFix窗口中列出所有符合條件的搜索結果

用GVim建立IDE編程環境(Win篇)

9、h\c切換(針對C、C++)

下載插件:a.vim 地址http://www.vim.org/scripts/download_script.php?src_id=7218

將a.vim復制到d:\Program Files\Vim\vim73\plugin,在_vimrc中添加: 
nnoremap :A 
用gvim打開源碼文件后,按F12即可以在c/h文件中切換,也可以通過輸入:A實現。

10、高亮書簽

下載插件:visualmark.vim 地址http://www.vim.org/scripts/download_script.php?src_id=4700

將visualmark.vim復制到d:\Program Files\Vim\vim73\plugin。 
用gvim打開源碼文件,將光標定位在需要添加書簽的地方,按下ctrl+F2,即添加了書簽。

用GVim建立IDE編程環境(Win篇)

使用F2在書簽之間正向切換,shift+F2反向切換。

11、Python代碼補全

下載插件pydiction-1.2.zip

解壓后,將里面的python_pydiction.vim文件復制到D:\Program Files\Vim\vimfiles\ftplugin

將complete-dict 和 pydiction.py復制到D:\Program Files\Vim\vimfiles\ftplugin\pydiction

在_vimrc文件中增加配置如下:

filetype plugin on  “啟用filetype插件

let g:pydiction_location = 'D:\Program Files\Vim\vimfiles\ftplugin\pydiction\complete-dict' 
let g:pydiction_menu_height = 20 ”設置彈出菜單的高度,默認是15

用gvim打開一個py文件,輸入row+[tab],就可以看到自動補全的代碼選項了

用GVim建立IDE編程環境(Win篇)

12、python編譯

下載VimPdb,解壓后拷貝VimPdb.py,VimPdb.vim到plugin即可。

用vim代開python代碼文件,按F5運行,然后按F2設置斷點,在運行到斷點后可以用按F12可以查看Stack Trace,F3查看變量和參數值。

用GVim建立IDE編程環境(Win篇)

不過這種方法使用了一下,經常會死掉,不知道為什么,所以在網上找到了另外一種方法:

在_vimrc增加

用GVim建立IDE編程環境(Win篇)

python << EOF import time
import vim
def SetBreakpoint():
    nLine = int( vim.eval( 'line(".")'))
    strLine = vim.current.line i = 0 strWhite = "" while strLine[i] == ' ' or strLine[i] == "\t":
        i += 1 strWhite += strLine[i] vim.current.buffer.append(
       "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
         {'space':strWhite, 'mark': '#' * 30}, nLine - 1)
    for strLine in vim.current.buffer:
        if strLine == "import pdb":
            break
        else:
            vim.current.buffer.append( 'import pdb', 0)
            vim.command( 'normal j1')
            break
vim.command( 'map  :py SetBreakpoint()')
 
def RemoveBreakpoints():
    nCurrentLine = int( vim.eval( 'line(".")'))
    nLines = []
    nLine = 1
    for strLine in vim.current.buffer:
        if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
            nLines.append( nLine)
        nLine += 1
    nLines.reverse()
    for nLine in nLines:
        vim.command( 'normal %dG' % nLine)
        vim.command( 'normal dd')
        if nLine < nCurrentLine: nCurrentLine -= 1 vim.command( 'normal %dG' % nCurrentLine)
vim.command( 'map  :py RemoveBreakpoints()')
vim.command( 'map  :!python %')
EOF

用GVim建立IDE編程環境(Win篇)

然后在要調試的代碼里面用ctrl-M設斷點 
ctrl-D運行

用GVim建立IDE編程環境(Win篇)

 

用GVim建立IDE編程環境(Win篇)

 

13、Python代碼檢查

下載pyflakes,解壓縮后把pyflakes.vim文件和pyflakes目錄拷貝套ftplugin\python目錄中打開一個有問題的python源代碼文件,執行命令:cc,即可進行代碼檢查:

用GVim建立IDE編程環境(Win篇)

set nocompatible "使用vim的鍵盤布局
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

filetype on                  "偵測文件類型插件
filetype plugin on       "為特定文件類型載入相關縮進文件
filetype indent on       "為特定文件類型載入相關縮進文件


syntax on              "語法高亮
syntax enable
colo torte              "設置配色方案


set nu                        "設置行號
set autoread              " 文件被改動時自動載入
set cursorline             "高亮顯示當前行
set nobackup             "不要備份文件
set wildmenu             "增加模式中的命令行自動完成操作


"可以在buffer的任何地方使用鼠標
set mouse=a
set selection=exclusive
set selectmode=mouse,key


set shortmess=atI      "去掉啟動的援助提示
set noerrorbells         "取消vim的滴滴聲
set showmatch          "高亮顯示匹配的括號
set matchtime=5        "匹配括號高亮的時間 十分之一秒
set ignorecase           "搜索時忽略大小寫,這個很實用
set incsearch             "搜索時,輸入的詞句逐字符高亮
set ruler                      "右下角顯示光標位置的狀態行
set hlsearch               "高亮顯示搜索結果


set autoindent             "繼承前一行的縮進方式
set smartindent           "開啟新行是使用智能自動縮進
set cindent                  "使用c樣式的縮進
set tabstop=4              "制表符為4
set softtabstop=4
set shiftwidth=4          "統一縮進為4
set noexpandtab         "不要用空格代替制表符
set showmode            "顯示文本處理模式
set confirm                  "處理未保存或者只讀文件時,給出提示
set fileencoding=utf-8 "文件保存編碼

set fileencodings=utf-8,gb2312,gbk,gb18030,cp936  "文件載入時檢測的編碼

set guioptions-=T        "注意 = 前面 有 - 號 ,隱藏不常用到的工具條

set guifont=YaHei_Consolas_Hybrid:h13:cANSI   " 注意 ANS后面的字母是大寫的 i 。。。如果自己安裝了字體,在字體選擇里面能看見你安裝的font,例如它的名字是 YaHei  Consolas   Hybrid 的話,用下劃線連接成:YaHei_Consolas_Hybrid,字母大小寫也區分,否則不能識別。。。加載無效果,h后面的數字是字體大小,根據需 要設置即可。。



=====================================================

近段時間一直實用vim進行編程,常用的操作已然熟悉,感覺還不錯,效率比起ue來要高,

開始感覺vim在windows下不能和ue相比的就是其不具備ftp功能,不能把windows下的文件

和linux的文件進行交互編輯,最近發現gvim7.2自帶的netrw插件能實現這個遠程編輯文

件的小功能,感覺還可以,同時把自己搜集整理的配置文件_vimrc做一個網絡備份,用

了幾個常用的插件功能:

minibuffer、nerd_commenter,SearchComplete,winmanager,perl-support,netrw

文件中有各種配置的詳細中文說明,以后想要隨時隨地使用還可以參考vim的中文幫助文

檔修改vimrc配置文件。


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" windows gvim設定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般設定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 配置多語言環境,解決中文亂碼問題
if has("multi_byte")
   " UTF-8 編碼
   set encoding=utf-8
   set termencoding=utf-8
   set formatoptions+=mM
   set fencs=utf-8,gbk

   if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
       set ambiwidth=double
   endif

   if has("win32")
       source $VIMRUNTIME/delmenu.vim
       source $VIMRUNTIME/menu.vim
       language messages zh_CN.utf-8
   endif
else
   echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif

" set mapleader
"譯注:映射快捷鍵開始命令為","號,g:表示全局設置.其使用方法見下
let mapleader = ","
let g:mapleader = ","

"那么這里可以用,w命令來代替:w!命令,親自試一下,是不是方便多了,手不
"用再挪大半個鍵盤打幾個鍵了.mapleader可以自由設定
nmap w :w!
nmap q :q
nmap wq :wq

if has("win32")
 "本句的意思是快速重讀配置文件,這樣,就不需要關閉文件重開一下來讀入
 map s :source $vim/_vimrc
 "譯注:上面的那一句看懂了,這句就很簡單了,這是快速打開配置文件
 map e :call SwitchToBuf("$vim/_vimrc")
 "譯注:autocmd是自動執行命令,這句的意思是當配置文件被更改后重新
 autocmd! bufwritepost _vimrc source $vim/_vimrc
else
 map s :source ~/.vimrc
 map e :call SwitchToBuf("~/.vimrc")
 autocmd! bufwritepost .vimrc source ~/.vimrc
endif

" 不要使用vi的鍵盤模式,而是vim自己的
set nocompatible

" history文件中需要記錄的行數
set history=1024

" 偵測文件類型
filetype on

" 載入文件類型插件
filetype plugin on

" 為特定文件類型載入相關縮進文件
filetype indent on

" 帶有如下符號的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-

" 語法高亮
syntax on
syntax enable

" 設置配色方案
colo torte

"顯示行號
set nu

set lbr

" 設置當文件被改動時自動載入
set autoread

" 高亮當前行
set cursorline

" 讓 gvim 支持 Alt+n 來切換標簽頁
autocmd VimEnter * call BufPos_Initialize()

" 譯注:設置文件類型,是UNIX文件,DOS文件還是Mac文件
set ffs=unix,dos,mac "Default file types

" When you press gv you vimgrep after the selected text
vnoremap gv :call VisualSearch('gv')

" => Fuzzy finder
try
   call fuf#defineLaunchCommand('FufCWD', 'file', 'fnamemodify(getcwd(), ''%:p:h'')')
   map t :FufCWD **/
catch
endtry

"譯注:本句的作用是移走Windows下的^M字符
noremap m mmHmt:%s///ge'tzt'm

"譯注:在指定目錄下創建一個臨時文件
map q :e ~/buffer

" 用戶目錄變量$VIMFILES
if has("win32")
   let $VIMFILES = $VIM.'/vimfiles'
else
   let $VIMFILES = $HOME.'/.vim'
endif

"保存一下,是不是超酷的效果啊,顏色請自行配置,一定要和背景色有反差
" 光標十字架
if has("gui_running")
set cursorline
 hi cursorline guibg=#333333
 set cursorcolumn
 hi CursorColumn guibg=#333333
endif

"譯注:切換到當前目錄
map cd :cd %:p:h


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件設置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 不要備份文件(根據自己需要取舍)
set nobackup

" 不要生成swap文件,當buffer被丟棄的時候隱藏它
setlocal noswapfile
set bufhidden=hide

" 增強模式中的命令行自動完成操作
set wildmenu

" 在狀態行上顯示光標所在位置的行號和列號
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)

" 命令行(在狀態行下)的高度,默認為1,這里是2
set cmdheight=1

" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2
set backspace=eol,start,indent

" 允許backspace和光標鍵跨越行邊界
set whichwrap+=<,>,h,l

" 可以在buffer的任何地方使用鼠標(類似office中在工作區雙擊鼠標定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key

" 啟動的時候不顯示那個援助索馬里兒童的提示
"set shortmess=atI

" 通過使用: commands命令,告訴我們文件的哪一行被改變過
set report=0

" 不讓vim發出討厭的滴滴聲
set noerrorbells

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 高亮顯示匹配的括號
set showmatch

" 匹配括號高亮的時間(單位是十分之一秒)
set matchtime=5

" 在搜索的時候忽略大小寫
set ignorecase

" 在搜索時,輸入的詞句的逐字符高亮(類似firefox的搜索)
set incsearch

" 輸入:set list命令是應該顯示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$

" 光標移動到buffer的頂部和底部時保持3行距離
set scrolloff=3

" 不要閃爍
set novisualbell

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"狀態行顯示內容
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"狀態行顯示內容
" %F 當前文件名
" %m 當前文件修改狀態
" %r 當前文件是否只讀
" %Y 當前文件類型
" %{&fileformat} 當前文件編碼
" %b 當前光標處字符的 ASCII 碼值
" %B 當前光標處字符的十六進制值
" %l 當前光標行號
" %c 當前光標列號
" %V 當前光標虛擬列號 (根據字符所占字節數計算)
" %p 當前行占總行數的百分比
" %% 百分號
" %L 當前文件總行數
" 我的狀態行顯示的內容(包括文件類型和解碼)
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
" 顯示狀態欄 (默認值為 1, 無法顯示狀態欄)
" 譯注:默認情況下,只有兩個以上的窗口才顯示狀態欄.其值定義為
" 本選項的值影響最后一個窗口何時有狀態行:
" 0: 永不
" 1: 只有在有至少兩個窗口時
" 2: 總是
set laststatus=2

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Set 7 lines to the curors - when moving vertical..
set so=7

"Do not redraw, when running macros.. lazyredraw
set lz

"Change buffer - without saving
set hid

"Set magic on
set magic

"How many tenths of a second to blink
set mat=2

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 自動格式化
"set formatoptions=tcrqn

" 繼承前一行的縮進方式,特別適用于多行注釋
set autoindent

"譯注:開啟新行時使用智能自動縮進
set smartindent

" 使用C樣式的縮進
"set cindent

" 制表符為4
set tabstop=4

" 統一縮進為4
set softtabstop=4
set shiftwidth=4

" 不要用空格代替制表符
set noexpandtab

" 不要換行
"set nowrap

" 在行和段開始處使用制表符
set smarttab

" 設置每行120個字符自動換行
"set textwidth=120

" 折疊代碼
set foldenable             " 開始折疊
set foldmethod=syntax      " 設置語法折疊
set foldcolumn=0           " 設置折疊區域的寬度
setlocal foldlevel=1       " 設置折疊層數為
set foldlevel=100          " 文件打開時不折疊
set foldclose=all          " 設置為自動關閉折疊                           

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"菜單欄、工具欄顯示與隱藏的切換
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set guioptions-=T
set guioptions-=m
map :if &guioptions =~# 'T'
\set guioptions-=T
\set guioptions-=m
\else
\set guioptions+=T
\set guioptions+=m
\endif

"窗口最大化
au GUIEnter * simalt ~x "maximum the initial window

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"自動實例括號
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" vnoremap可視模式,使用$1來輸入()
vnoremap $1 `>a)`
" 使用$2來輸入()
vnoremap $2 `>a]`
" 使用$3來輸入()
vnoremap $3 `>a}`
" 使用$$來輸入()
vnoremap $$ `>a"`
" 使用$q來輸入()
vnoremap $q `>a'`
" 使用$e來輸入()
vnoremap $e `>a"`

inoremap $1 ()i
inoremap $2 []i
inoremap $3 {}i
inoremap $4 {o}O
inoremap $q ''i
inoremap $e ""i

"用于編輯中文的前后雙引號,自己編輯常用的成對符號時,一定要注意,
"前面的符號放在a后,不要反了
vnoremap $w `>a"`
"vnoremap $w `>a>`
"vnoremap $w '>a”`

" 用空格鍵來開關折疊
set foldenable
set foldmethod=manual
nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Command mode related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./
cno $c e eCurrentFileDir("e")

" $q is super useful when browsing on the command line
cno $q eDeleteTillSlash()

" 在vim冒號命令行可以像linux命令行一樣使用ctrl+[aekpn]
cnoremap      
cnoremap      
cnoremap      

" 在命令行模式下使用alt+[jk]可以讓光標后的文本向上或向下移動
" 在插入模式下使用ctrl+[jk]可以讓光標后的文本向上或向下移動
" 上面兩行是gvim自己就有的功能


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / (search) and c-space to ? (backgwards search)
"map /
"map ?
"map :noh

" 譯注:窗口分割時,進行切換的按鍵熱鍵需要連接兩次,比如從下方窗口移動
"光標到上方窗口,需要k,非常麻煩,現在重映射為,切換的
"時候會變得非常方便.
map j
map k
map h
map l

" 譯注: ,bd命令快速關閉當前緩沖區文件
map bd :Bclose

" 譯注: ,ba命令快速關閉所有緩沖區文件
map ba :1,300 bd!

" Tab configuration
map tn :tabnew % " 譯注:將當前內容在新標簽中打開
map te :tabedit     " 譯注:打開空白新標簽
map tc :tabclose " 譯注:關閉當前標簽
map tm :tabmove     " 譯注:移動當前標簽,使用方法為

" When pressing cd switch to the directory of the open buffer
map cd :cd %:p:h

" Specify the behavior when switching between buffers
"try
 "set switchbuf=usetab
 "set stal=2
"catch
"endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 插件
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" minibufexpl插件的一般設置
"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplModSelTarget = 1
" minibuffer操作快捷方式!
nnoremap :MBEbn
nnoremap :MBEbp
"let g:bufExplorerDefaultHelp=0
"let g:bufExplorerShowRelativePath=1
"譯注:右方向鍵切換到下一個緩沖區文件
" map :bn
"譯注:左方向鍵切換到上一個緩沖區文件
" map :bp
"譯注:刪除一個緩沖區文件時,不關閉窗口


" plugin - NERD_commenter.vim  注釋代碼用的,
" [count],cc 光標以下count行逐行添加注釋(7,cc)
" [count],cu 光標以下count行逐行取消注釋(7,cu)
" [count],cm 光標以下count行嘗試添加塊注釋(7,cm)
" ,cA 在行尾插入 ,并且進入插入模式。 這個命令方便寫注釋。
" 注:count參數可選,無則默認為選中行或當前行
"-----------------------------------------------------------------
let NERDSpaceDelims=1      " 讓注釋符與語句之間留一個空格
let NERDCompactSexyComs=1  " 多行注釋時樣子更好看

" win manager
" 布局規劃變量
let g:winManagerWindowLayout = 'FileExplorer'
let g:winManagerWidth = 30
let g:defaultExplorer = 0
map :FirstExplorerWindow
map :BottomExplorerWindow
map :WMToggle

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 函數定義
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" if file not opened, create a new tab, or switch to the opened file
function! SwitchToBuf(filename)
 " find in current tab
 let bufwinnr = bufwinnr(a:filename)
 if bufwinnr != -1
 exec bufwinnr . "wincmd w"
 return
 else
 " search each tab
 tabfirst
 let tb = 1
 while tb <= tabpagenr("$")
 let bufwinnr = bufwinnr(a:filename)
 if bufwinnr != -1
 exec "normal " . tb . "gt"
 exec bufwinnr . "wincmd w"
 return
 endif
 tabnext
 let tb = tb +1
 endwhile
 " not exist, new tab
 exec "tabnew " . a:filename
 endif
endfunction


function! MyDiff()
 let opt = '-a --binary '
 if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
 if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
 let arg1 = v:fname_in
 if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
 let arg2 = v:fname_new
 if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
 let arg3 = v:fname_out
 if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
 let eq = ''
 if $VIMRUNTIME =~ ' '
   if &sh =~ '\      let cmd = '""' . $VIMRUNTIME . '\diff"'
     let eq = '"'
   else
     let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
   endif
 else
   let cmd = $VIMRUNTIME . '\diff'
 endif
 silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction


function! BufPos_ActivateBuffer(num)
 let l:count = 1
 for i in range(1, bufnr("$"))
 if buflisted(i) && getbufvar(i, "&modifiable")
 if l:count == a:num
 exe "buffer " . i
 return
 endif
 let l:count = l:count + 1
 endif
 endfor
 echo "No buffer!"
endfunction
function! BufPos_Initialize()
 for i in range(1, 9)
 exe "map :call BufPos_ActivateBuffer(" . i . ")"
 endfor
 exe "map :call BufPos_ActivateBuffer(10)"
endfunction

" From an idea by Michael Naumann
function! VisualSearch(direction) range
   let l:saved_reg = @"
   execute "normal! vgvy"

   let l:pattern = escape(@", '\\/.*$^~[]')
   let l:pattern = substitute(l:pattern, "\n$", "", "")

   if a:direction == 'b'
       execute "normal ?" . l:pattern . "^M"
   elseif a:direction == 'gv'
       call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
   elseif a:direction == 'f'
       execute "normal /" . l:pattern . "^M"
   endif

   let @/ = l:pattern
   let @" = l:saved_reg
endfunction

function! CmdLine(str)
   exe "menu Foo.Bar :" . a:str
   emenu Foo.Bar
   unmenu Foo
endfunction


" 譯注:簡單說一下其功能,設置了一個函數CurDir(),該函數調用了getcwd()
" 函數,getcwd()的作用是返回當前路徑這個值.
function! CurDir()
   let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
   return curdir
endfunction


func! Cwd()
 let cwd = getcwd()
 return "e " . cwd
endfunc


command! Bclose call BufcloseCloseIt()
function! BufcloseCloseIt()
  let l:currentBufNum = bufnr("%")
  let l:alternateBufNum = bufnr("#")

  if buflisted(l:alternateBufNum)
    buffer #
  else
    bnext
  endif

  if bufnr("%") == l:currentBufNum
    new
  endif

  if buflisted(l:currentBufNum)
    execute("bdelete! ".l:currentBufNum)
  endif
endfunction

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!