日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
基于Ubuntu16.04配置VimIDE

1.序言        

本文是本人在ubuntu 16.04上Vim IDE搭建過(guò)程的總結(jié)。在Windows環(huán)境開(kāi)發(fā)的小伙伴也許都知道sourceinsight這款編輯器,為了提高Linux下開(kāi)發(fā)效率,本人搭建了類(lèi)sourceinsight的IDE開(kāi)發(fā)環(huán)境(勉強(qiáng)稱(chēng)作VIM IDE吧:))。

廢話不多,先上圖展示本人的VIM IDE。 一個(gè)窗口同時(shí)顯示了4個(gè)子終端窗口(當(dāng)然也可以有更多),每一個(gè)子終端窗口類(lèi)似sourceinsight又切分成了3欄(左下Taglist欄-顯示函數(shù),宏等標(biāo)簽;左上filelist欄-顯式代碼文件目錄文件結(jié)構(gòu); 右側(cè)欄-代碼編輯區(qū))。 如果我們看著窗口字太小,沒(méi)關(guān)系, 當(dāng)編輯程序時(shí)候你可以選擇4個(gè)子終端窗口中要編輯的那個(gè)終端單獨(dú)放大全屏顯示(terminator安裝后Ctrl+shit+X),編輯完成之后仍然可以切換回來(lái)(terminator安裝后Ctrl+shift+Z)。

2. 配置過(guò)程

    如果要完成以上顯示效果,我們需要安裝一些必要的工具和插件,下面將逐步展開(kāi)。

2.1 Terminator 安裝

      工具Terminator可以在一個(gè)窗口中顯示多個(gè)終端窗口,并且可以按照用戶的要求對(duì)窗口進(jìn)行任意分割。

      Ubuntu環(huán)境安裝terminator工具命令為:sudo apt-get install terminator

      Terminator常用快捷按鍵有:

    1)Ctrl+Shift+E垂直分割窗口

      2)Ctrl+Shift+O 水平分割窗口

      3)Ctrl+Tab  在分割的窗口間切換

      4)Ctrl+Shift+C/V 復(fù)制/粘貼

      5)Ctrl+Shift+X 放大窗口到全屏

      6)Ctrl+Shift+Z 從放大窗口回到多窗口

      注意:如果您對(duì)窗口風(fēng)格不滿意,可以右鍵->preferences進(jìn)行必要設(shè)置和修改。比如修改快捷按鍵等等。

2.2 vim 編輯器安裝

      Ubuntu環(huán)境安裝terminator工具命令為: sudo apt-get install vim vim-scripts vim-doc

     其中vim-scripts是vim的一些基本插件 ,vim安裝之后緊接著應(yīng)該個(gè)性化配置。Vim本身的系統(tǒng)配置文件夾是在/usr/share/vim/和/etc/vim/兩個(gè)文件夾下。但是通常我們不會(huì)去改變這兩個(gè)文件夾下的配置文件,而是在用戶文件夾/home/user下建立自己的配置文件.vimrc然后對(duì)其配置,這里不再解釋?zhuān)竺嫖覍⒏缴衔业膙im配置。

 

2.3 vim插件安裝

    vim常用插件有:1)vim-addons 2)ctags 3)cscope 4)winmanager 5)minibufexplorer 6)omnicppcomplete 7)AutoComplPop  8)echofunc 9)taglist

2.3.1 vim-addons

  通過(guò)vim-addons,我們可以管理vim插件??赏ㄟ^(guò)命令sudo apt-get install vim-addon-manager手動(dòng)安裝。

  查看插件狀態(tài) 命令: vim-addons status

# Name                    User Status  System Status
align                      removed      removed       
alternate                  removed      removed       
bufexplorer                removed      removed       
calendar                    removed      removed       
closetag                    removed      removed       
colors-sampler-pack        removed      removed       
cvsmenu                    removed      removed       
debPlugin                  removed      removed       
detectindent                removed      removed       
doxygen-toolkit            removed      removed       
editexisting                removed      removed       
enhanced-commentify        removed      removed       
gnupg                      removed      removed       
info                        removed      removed       
justify                    removed      removed       
lbdbq                      removed      removed       
matchit                    removed      removed       
minibufexplorer            installed    removed       
nerd-commenter              removed      removed       
omnicppcomplete            installed    removed       
po                          removed      removed       
project                    installed    removed       
python-indent              removed      removed       
secure-modelines            removed      removed       
snippetsEmu                removed      removed       
sokoban                    removed      removed       
supertab                    removed      removed       
surround                    removed      removed       
taglist                    installed    removed       
tetris                      removed      removed       
utl                        removed      removed       
vcscommand                  removed      removed       
vimplate                    removed      removed       
whatdomain                  removed      removed       
winmanager                  installed    removed       
xmledit                    removed      removed

    安裝某個(gè)插件X命令(前提是在目錄/home/user/.vim/下建立好了plugin和doc兩個(gè)文件夾):vim-addons install X

2.3.2 ctags

    ctags用來(lái)建立源碼樹(shù)的標(biāo)簽索引(標(biāo)簽就是一個(gè)標(biāo)識(shí)符被定義的地方,如函數(shù)定義),在編程時(shí)能迅速定位函數(shù)、變量、宏定義等位置去查看原形。
    1)ctags安裝命令

          sudo apt-get install ctags

    2)ctags配置

        要正確使用ctags功能,我們也需要配置vimrc文件,我將在附件列舉。

    3)建立項(xiàng)目project的源碼索引命令(通常在項(xiàng)目project文件夾根目錄執(zhí)行)

          ctags -R *

          執(zhí)行以上命令之后,你會(huì)發(fā)現(xiàn)多了一個(gè)tags文件,這個(gè)就是ctags索引文件。

    4)ctags常用方法

          Ctrl+]  跳到當(dāng)前光標(biāo)下單詞的標(biāo)簽
          Ctrl+O  返回上一個(gè)標(biāo)簽
          Ctrl+T  返回上一個(gè)標(biāo)簽
        Ctrl+W + ]  新窗口顯示當(dāng)前光標(biāo)下單詞的標(biāo)簽,光標(biāo)跳到標(biāo)簽處

2.3.3 cscope

      cscope是類(lèi)似于ctags一樣的工具,但??比ctags更強(qiáng)大。

     1)cscope安裝命令

          sudo apt-get install cscope

    2)cscope配置

        要正確使用cscope功能,我們也需要配置vimrc文件,我將在附件列舉。

    3)建立項(xiàng)目project的源碼cscope數(shù)據(jù)庫(kù)命令(通常在項(xiàng)目project文件夾根目錄執(zhí)行)

          cscope -Rbq cscope.out

          執(zhí)行以上命令之后,你會(huì)發(fā)現(xiàn)多了3個(gè)文件,cscope.in.out,cscope.po.out, cscope.out, 它們就是cscope索引數(shù)據(jù)庫(kù)。

        注意:以上命令收集的是project目錄下cscope缺省類(lèi)型文件索引,有時(shí)候我們自定義文件不能索引,所以我們可以用如下命令替換以上命令:

        find  .  -name "*.h" -o -name "*.cpp" -o -name "*.c" > cscope.file

        cscope -bqk -i cscope.file

    4)添加cscope庫(kù)到vim

        對(duì)于簡(jiǎn)單1個(gè)文件,用vim打開(kāi)某個(gè)源碼文件,末行模式下,輸入“:cs add cscope.out"。對(duì)于整個(gè)project工程文件,我們需要借助vim自己讀取配置文件。

        我是在用戶目錄~/.vim/plugin/下放置了cscope_map.vim配置文件,后面會(huì)附上。

    5)cscope常用方法

      Ctrl-\ s 查找所有當(dāng)前光標(biāo)所在符號(hào)出現(xiàn)過(guò)位置。
      Ctrl-\ c 查找所有調(diào)用當(dāng)前光標(biāo)所在函數(shù)的函數(shù)。

      當(dāng)然還有其它按鍵,請(qǐng)閱讀配置文件或者在vim命令行執(zhí)行:help cscope

    注意:通過(guò)快捷鍵查找某個(gè)符號(hào)后,會(huì)立即跳轉(zhuǎn)到第一個(gè)找到的該符號(hào)出現(xiàn)的位置。如果你對(duì)這次默認(rèn)跳轉(zhuǎn)的位置不滿意,在Vim命令行下運(yùn)行cw命令,就能在編輯區(qū)下面quickfix窗口看到所有查找結(jié)果的列表,點(diǎn)擊相應(yīng)列表項(xiàng)就能跳轉(zhuǎn)到相應(yīng)位置。

2.3.4  winmanager

    WinManager用于管理文件瀏覽器和緩沖區(qū)(buffer)。

    安裝命令為:vim-addons install winmanager

    配置見(jiàn)附錄vimrc,進(jìn)入vim之后打開(kāi)或者關(guān)閉命令是輸入:WMToggle

2.3.5 minibufexplorer

    安裝命令為:vim-addons install minibufexplorer

    配置見(jiàn)附錄vimrc

2.3.6 omnicppcomplete(自動(dòng)補(bǔ)齊)

  安裝命令為:vim-addons install omnicppcomplete

  配置文件見(jiàn)附錄vimrc

2.3.7 AutoComplPop(普通變量和函數(shù)自動(dòng)彈出補(bǔ)齊)

      下載鏈接:http://www.vim.org/scripts/script.php?script_id=1879 

        安裝方法:

               先解壓:unzip vim-autocomplpop.zip,將解壓后的文件拷貝到~/.vim/ 下的相應(yīng)目錄里:

                     autoload/*    ->    ~/.vim/autoload/

                     doc/*    ->    ~/.vim/doc/

                     plugin/*    ->    ~/.vim/plugin/

      幫助使用:

              重新打開(kāi)vim即可使用。添加help文件:helptags ~/.vim/doc/即可(打開(kāi)幫助文件:help autocomplpop)

2.3.8 echofunc(函數(shù)原型提示)

    echofunc下載地址:http://www.vim.org/scripts/script.php?script_id=1735
    下載完成后,把echofunc.vim文件放到 ~/.vim/plugin文件夾中
    當(dāng)在vim插入(insert)模式下緊接著函數(shù)名后輸入一個(gè)"("的時(shí)候, 這個(gè)函數(shù)的聲明就會(huì)自動(dòng)顯示在信息提示欄。

    注意:這個(gè)插件需要tags文件的支持, 并且在創(chuàng)建tags文件的時(shí)候要加選項(xiàng)"--fields=+lS"。  ctags -R --field=+IS

2.3.9 taglist

      taglist用于列出了當(dāng)前文件中的所有標(biāo)簽(宏, 全局變量, 函數(shù)名等)。
    安裝Taglist命令: vim-addons install taglist

      配置見(jiàn)附錄vimrc,進(jìn)入vim之后關(guān)閉或者打開(kāi)taglist方法是末行命令模式輸入:Taglist。

2.3.10 quickfix

      在程序的開(kāi)發(fā)過(guò)程中,很重要的一個(gè)循環(huán)是:編輯-編譯-編輯,vim中的quickfix功能就是為了提高這一循環(huán)的效率。

    推薦使用Makefile的方式進(jìn)行項(xiàng)目的編譯、管理,可以實(shí)現(xiàn)項(xiàng)目的自動(dòng)化管理、有利于提高效率。通過(guò)make命令完成程序的編譯工作后,會(huì)得到編譯結(jié)果,一般會(huì)有一些編譯錯(cuò)誤,quickfix功能使我們可以直接跳到文件中的錯(cuò)誤位置,直接進(jìn)行修改,并通過(guò)使用quickfix的命令完成錯(cuò)誤列表的跳轉(zhuǎn)。

    如果僅有1個(gè)文件也懶得寫(xiě)Makefile文件,可以采用如下2條命令處理:

    :set makeprg=gcc\ test.c\ -o\ test

    :make     變量的值為字符串,當(dāng)在其中有空格時(shí)需要用\進(jìn)行轉(zhuǎn)義,同樣如果想輸入\也要進(jìn)行轉(zhuǎn)義。

    注意:在vim運(yùn)行時(shí)通過(guò)命令行設(shè)置的變量值均是臨時(shí)的,即當(dāng)退出vim環(huán)境時(shí),該變量值會(huì)恢復(fù)為配置文件中的值或者默認(rèn)值。

   

        常用的quickfix命令為:     :cc     顯示詳細(xì)錯(cuò)誤信息     :cp     跳到上一個(gè)錯(cuò)誤     :cn     跳到下一個(gè)錯(cuò)誤     :cl      列出所有錯(cuò)誤     :cw     如果有錯(cuò)誤列表,則打開(kāi)quickfix窗口,沒(méi)有則什么也不錯(cuò)

3. 附錄

3.1 vimrc設(shè)置

    下面是我的vimrc配置,這個(gè)文件放在目錄/home/user/下。

runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
set nocompatible

" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
   syntax on
endif
colorscheme ron  

" detect file type
filetype on
filetype plugin on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
   au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
   "have Vim load indentation rules and plugins according to the detected filetype
   filetype plugin indent on
endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.

"set ignorecase
"set smartcase       
set autowrite       
set autoindent       
"set smartindent     
set tabstop=4       
set softtabstop=4  
set shiftwidth=4  
set cindent     
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s     
"set backspace=2   
set showmatch     
set linebreak     
set whichwrap=b,s,<,>,[,]
"set hidden " Hide buffers when they are abandoned
set mouse=a           
set number           
"set previewwindow   
set history=50     

set laststatus=2
set ruler           

set showcmd   
set showmode

"--find setting--
set incsearch       
set hlsearch   

"--ctags setting--
map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
imap :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
set tags=tags
set tags+=./tags "add current directory's generated tags file
"set tags+=~/test/tags

"-- omnicppcomplete setting --
imap
imap
set completeopt=menu,menuone
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 " enable the global scope search
let OmniCpp_DisplayMode=1 " Class scope completion mode: always show all members
"let OmniCpp_DefaultNamespaces=["std"]
let OmniCpp_ShowScopeInAbbr=1 " show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1

"-- Taglist setting --
let Tlist_Ctags_Cmd='ctags'
let Tlist_Use_Right_Window=1
let Tlist_Show_One_File=0
let Tlist_File_Fold_Auto_Close=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Process_File_Always=1
let Tlist_Inc_Winwidth=0

"-- WinManager setting --
let g:winManagerWindowLayout='FileExplorer|TagList'
"let g:persistentBehaviour=0
nmap wm :WMToggle

" -- MiniBufferExplorer --
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1   

"--fold setting--
set foldmethod=syntax
set foldlevel=100
set foldcolumn=5

"-- QuickFix setting --
map :make clean
map :make :copen
map :cp
map :cn
imap :make clean
imap :make :copen
imap :cp
imap :cn

3.2 cscope配置文件

  cscope配置文件位于目錄(/home/user/.vim/plugin)名叫cscope_map.vim,內(nèi)容為

 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CSCOPE settings for vim           
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" This file contains some boilerplate settings for vim's cscope interface,
" plus some keyboard mappings that I've found useful.
"
" USAGE:
" -- vim 6:    Stick this file in your ~/.vim/plugin directory (or in a
"              'plugin' directory in some other directory that is in your
"              'runtimepath'.
"
" -- vim 5:    Stick this file somewhere and 'source cscope.vim' it from
"              your ~/.vimrc file (or cut and paste it into your .vimrc).
"
" NOTE:
" These key maps use multiple keystrokes (2 or 3 keys).  If you find that vim
" keeps timing you out before you can complete them, try changing your timeout
" settings, as explained below.
"
" Happy cscoping,
"
" Jason Duell      jduell@alumni.princeton.edu    2002/3/7
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" This tests to see if vim was configured with the '--enable-cscope' option
" when it was compiled.  If it wasn't, time to recompile vim...
if has("cscope")

   set csprg=/usr/bin/cscope "指定用來(lái)執(zhí)行cscope的命令

    """"""""""""" Standard cscope/vim boilerplate

    " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
    set cscopetag
   set csto=0  "設(shè)置cstag命令查找次序:0先找cscope數(shù)據(jù)庫(kù)再找標(biāo)簽文件;1先找標(biāo)簽文件再找cscope數(shù)據(jù)庫(kù)"
   set cst                            "同時(shí)搜索cscope數(shù)據(jù)庫(kù)和標(biāo)簽文件
   set cscopequickfix=s-,c-,d-,i-,t-,e-    " 使用QuickFix窗口來(lái)顯示cscope查找結(jié)果
   
   set nocsverb

    " add any cscope database in current directory
    if filereadable("cscope.out")
        cs add cscope.out  
    " else add the database pointed to by environment variable
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif

    " show msg when any other cscope db added
   set csverb
  " set cscopeverbose  

    """"""""""""" My cscope/vim key mappings
    "
    " The following maps all invoke one of the following cscope search types:
    "
    "  's'  symbol: find all references to the token under cursor
    "  'g'  global: find global definition(s) of the token under cursor
    "  'c'  calls:  find all calls to the function name under cursor
    "  't'  text:  find all instances of the text under cursor
    "  'e'  egrep:  egrep search for the word under cursor
    "  'f'  file:  open the filename under cursor
    "  'i'  includes: find files that include the filename under cursor
    "  'd'  called: find functions that function under cursor calls
    "
    " Below are three sets of the maps: one set that just jumps to your
    " search result, one that splits the existing vim window horizontally and
    " diplays your search result in the new window, and one that does the same
    " thing, but does a vertical split instead (vim 6 only).
    "
    " I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
    " unlikely that you need their default mappings (CTRL-\'s default use is
    " as part of CTRL-\ CTRL-N typemap, which basically just does the same
    " thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
    " If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
    " of these maps to use other keys.  One likely candidate is 'CTRL-_'
    " (which also maps to CTRL-/, which is easier to type).  By default it is
    " used to switch between Hebrew and English keyboard mode.
    "
    " All of the maps involving the macro use '^$': this is so
    " that searches over '#include " return only references to
    " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
    " files that contain 'time.h' as part of their name).

    " To do the first type of search, hit 'CTRL-\', followed by one of the
    " cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
    " search will be displayed in the current window.  You can use CTRL-T to
    " go back to where you were before the search.  
    "

    nmap s :cs find s =expand("")   
    nmap g :cs find g =expand("")   
    nmap c :cs find c =expand("")   
    nmap t :cs find t =expand("")   
    nmap e :cs find e =expand("")   
    nmap f :cs find f =expand("")   
    nmap i :cs find i ^=expand("")$
    nmap d :cs find d =expand("")   

    " Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
    " makes the vim window split horizontally, with search result displayed in
    " the new window.
    "
    " (Note: earlier versions of vim may not have the :scs command, but it
    " can be simulated roughly via:
    "    nmap s :cs find s =expand("")   

    nmap s :scs find s =expand("")   
    nmap g :scs find g =expand("")   
    nmap c :scs find c =expand("")   
    nmap t :scs find t =expand("")   
    nmap e :scs find e =expand("")   
    nmap f :scs find f =expand("")   
    nmap i :scs find i ^=expand("")$   
    nmap d :scs find d =expand("")   

    " Hitting CTRL-space *twice* before the search type does a vertical
    " split instead of a horizontal one (vim 6 and up only)
    "
    " (Note: you may wish to put a 'set splitright' in your .vimrc
    " if you prefer the new window on the right instead of the left

    nmap s :vert scs find s =expand("")
    nmap g :vert scs find g =expand("")
    nmap c :vert scs find c =expand("")
    nmap t :vert scs find t =expand("")
    nmap e :vert scs find e =expand("")
    nmap f :vert scs find f =expand("")   
    nmap i :vert scs find i ^=expand("")$   
    nmap d :vert scs find d =expand("")

    """"""""""""" key map timeouts
    "
    " By default Vim will only wait 1 second for each keystroke in a mapping.
    " You may find that too short with the above typemaps.  If so, you should
    " either turn off mapping timeouts via 'notimeout'.
    "
    "set notimeout
    "
    " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
    " with your own personal favorite value (in milliseconds):
    "
    "set timeoutlen=4000
    "
    " Either way, since mapping timeout settings by default also set the
    " timeouts for multicharacter 'keys codes' (like ), you should also
    " set ttimeout and ttimeoutlen: otherwise, you will experience strange
    " delays as vim waits for a keystroke after you hit ESC (it will be
    " waiting to see if the ESC is actually part of a key code like ).
    "
    "set ttimeout
    "
    " personally, I find a tenth of a second to work well for key code
    " timeouts. If you experience problems and have a slow terminal or network
    " connection, set it higher.  If you don't set ttimeoutlen, the value for
    " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
    "
    "set ttimeoutlen=100

endif

3.3 ctags和cscope腳本

    為方便使用,如下寫(xiě)到一個(gè)腳本中,在創(chuàng)建工程project之后調(diào)用一下即可創(chuàng)建tags索引和cscope數(shù)據(jù)庫(kù)。

#!/bin/sh

ctags -R --fields=+lS

find . -name "*.h" -o -name "*.c" -o -name "*.cpp" > cscope.files
cscope -bkq -i cscope.files


網(wǎng)站欄目:基于Ubuntu16.04配置VimIDE
網(wǎng)頁(yè)鏈接:http://www.dlmjj.cn/article/djjiejp.html