码迷,mamicode.com
首页 > 系统相关 > 详细

Make Vim an IDE

时间:2015-12-28 22:02:32      阅读:662      评论:0      收藏:0      [点我收藏+]

标签:

Making vim an IDE is an exiting thing. Conside following configuration files:

  • .vimrc: ~/.vimrc
  • winmanager.vim: ~/.vim/bundle/winmanager/plugin/winmanager.vim

.vimrc

my .vimrc is as follows:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin ‘VundleVim/Vundle.vim‘

" My Bundles here
"
" original repos on github
Bundle ‘tpope/vim-fugitive‘
Bundle ‘Lokaltog/vim-easymotion‘
Bundle ‘rstacruz/sparkup‘, {‘rtp‘: ‘vim/‘}
Bundle ‘tpope/vim-rails.git‘
Bundle ‘The-NERD-tree‘
Bundle ‘The-NERD-Commenter‘
Bundle ‘taglist.vim‘
Bundle ‘winmanager‘

" vim-scripts repos
Bundle ‘L9‘
Bundle ‘FuzzyFinder‘

" non github repos
Bundle ‘git://git.wincent.com/command-t.git‘
Bundle ‘bufexplorer.zip‘

" Color schemes
Bundle ‘tomasr/molokai‘
Bundle ‘flazz/vim-colorschemes‘
Bundle ‘evening_2‘
Bundle ‘Solarized‘

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

" Brief help
" " :PluginList       - lists configured plugins
" " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" " :PluginSearch foo - searches for foo; append `!` to refresh local cache
" " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" Put your non-Plugin stuff after this line

" Set <leader> to ‘,‘
let mapleader = ‘,‘

" Set color scheme
syntax on
" colorscheme molokai
colorscheme evening_2
" syntax enable
" set background=dark
" colorscheme solarized

" To change the number of space characters inserted for indentation
set shiftwidth=4
" To control the number of space characters that will be inserted when the tab key is pressed
" insert 4 spaces for a tab
set tabstop=4
" To insert space characters whenever the tab key is pressed
" if you want to enter a real tab character, use Ctrl-V<Tab> key sequence
set expandtab
" To display line numbers
set nu
" By pressing Ctrl-N twice in normal mode, 
" Vim toggles between showing and hiding line numbers.
nmap <C-N><C-N> :set invnumber<CR>
" make backspace work like most other apps
set backspace=2
" To display the status line always
set laststatus=2
" Do not create an swapfile
set noswapfile

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cscope
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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")
    " use both cscope and ctag for ‘ctrl-]‘, ‘:ta‘, and ‘vim -t‘
    set cscopetag

    " check cscope for definition of a symbol before checking ctags: set to 1
    " if you want the reverse search order.
    set csto=0

    " 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 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).
    "
    " 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 <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>  
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>

    " 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.
    nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-@>i :cs find i <C-R>=expand("<cfile>")<CR><CR>
    nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>

    " 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 <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
    nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>   
    nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR> 
    nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Taglist
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Specifies the path to the ctags utility
" let Tlist_Ctags_Cmd = ‘/usr/bin/ctags‘

" Increase the Vim window width to accommodate the taglist window
let Tlist_Inc_Winwidth = 0

" Jump to taglist window on open
let Tlist_GainFocus_On_ToggleOpen = 1

" Open the taglist window when Vim starts
let Tlist_Auto_Open = 1

" Automatically update the taglist to include
" newly edited files
let Tlist_Auto_Update = 1

" Close Vim if the taglist is the only window
let Tlist_Exit_OnlyWindow = 1

" Show tags for the current buffer only
let Tlist_Show_One_File = 1

" Process files even when the taglist window is closed
let Tlist_Process_File_Always = 1

" Display the tags menu
let Tlist_Show_Menu = 1

" Place the taglist window on the right side
let Tlist_Use_Right_Window = 1

" Automatically highlight the current tag in the taglist
let Tlist_Auto_Highlight_Tag = 0

nmap <silent> <leader>tg :TlistToggle<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WinManager
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Using ‘,wm‘ to open or close WinManage in normal mode
nmap <silent> <leader>wm :WMToggle<CR>

let g:NERDTree_title="[NERDTree]"
let g:winManagerWindowLayout=‘NERDTree|BufExplorer,TagList‘

function! NERDTree_Start()
    exec ‘NERDTree‘
endfunction

function! NERDTree_IsValid()
    return 1
endfunction

" Auto open WinManager
let g:AutoOpenWinManager=1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Main points of my vimrc

  • Use vundle to manage plugins;
  • Key pulgins: winmanager, taglist, nerdtree.

To use my vimrc

  1. copy my vimrc to your .vimrc
  2. open vim and execute command “: PluginInstall”
  3. Modify winmanager.vim

Modify winmanager.vim

Modify function ToggleWindowsManager

" toggle showing the explorer plugins.
function! <SID>ToggleWindowsManager()
    if IsWinManagerVisible()
        call s:CloseWindowsManager()
    else
        call s:StartWindowsManager()
        " Solve the bug that
        " an extra blank window will open
        " when WinManager opens
        exec ‘q‘
    end
endfunction

Add codes to set auto open WinManager

"set auto open WinManager
if g:AutoOpenWinManager
    autocmd VimEnter * nested call s:ToggleWindowsManager()|1wincmd w
end

Make Vim an IDE

标签:

原文地址:http://www.cnblogs.com/luckysimple/p/5083633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!