2013年4月16日 星期二

[分享] Tracing source code with vim mouse, gtags, ctags, taglist, winmanager.vim, minibufexplorer.vim, NERD_tree.vim

介紹如何建立VIM的工作環境達到與 Source Insight 與 Visual Studio 般的強大功能
1. gtags:
    gtags usage reference


2. 安裝與使用 ctags

    a) Download ctags 並解壓縮

    b) 進入ctags目錄並產生ctags執行檔

       cd ctags-5.8; ./configure; make

    c) 直接將產生出來的ctags 放置到 /usr/local/bin/ 或/usr/bin,若沒有權限寫入也可放置~/bin/中


    d) 進入要追蹤的原始碼目錄,執行下列指命產生原始碼的tags

       ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .

    e) 下載 ctags.vim,並放置到~/.vim/plugin


    f) 在VIM中,為ctags增加快捷鍵F12,打開~/.vimrc並增加下行指命

        map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>


3. 安裝與使用 taglist
    a) 下載 taglist,並解壓縮至~/.vim/plugin

    b) 打開~/.vimrc並增加下兩行指命
        let Tlist_Show_One_File=1
        let Tlist_Exit_OnlyWindow=1


4. 安裝與使用  winmanager.vim, minibufexplorer.vim, NERD_tree.vim
    a) 分別下載三個VIM plugins至~/.vim中並解壓縮
        NERD Tree
        Minibufexplorer
        Winmanager

     b) 增加下列數行程式碼至.vimrc中
         let g:miniBufExplMapWindowNavVim = 1
         let g:miniBufExplMapWindowNavArrows = 1
         let g:miniBufExplMapCTabSwitchBufs = 1
         let g:miniBufExplModSelTarget = 1
         let g:miniBufExplMoreThanOne=0
         let g:NERDTree_title="[NERDTree]"
         let g:winManagerWindowLayout="NERDTree|TagList"

         function! NERDTree_Start()
             exec 'NERDTree'
         endfunction

         function! NERDTree_IsValid()
             return 1
         endfunction 

         map :WMToggle

    c) 並修改winmanager.vim將NERD Tree造成的空白視窗關閉
        function! ToggleWindowsManager()
            if IsWinManagerVisible()
                call s:CloseWindowsManager()
            else
                call s:StartWindowsManager()
                exe '3wincmd w'
                exe 'q'
            end
        endfunction

5. 在VIM,中增加滑鼠功能
     map :if &number \| set nonumber \| else \| set number \| endif  
     ==> 使用F8開啟與關並行數顯示

     map :if &mouse == 'a' \| set mouse= \| else \| set mouse=a \| endif
     set ttymouse=xterm2
     ==> 使用F10開啟與關閉滑鼠功能

沒有留言:

張貼留言