分享

如何将VIM配置成适用C语言的IDE

 善哉善斋 2015-10-10

博客都快长了半年的草,整个换工作的过程也基本确定下来了,在前公司里做内核,还有souce insight可用来看代码,自己也就懒得折腾,到新公司后,source insight没得用了,只好把vim拿来配置,记录如下。

一般情况下的IDE长什么样子都是类似,最好界面如source insight这般,可以解决类似问题。

vim for souce_insight oanhan

vim for souce_insight oanhan

左边有类似的函数列表,中间是代码编辑区,右边则是代码文件列表,最下面则显示搜索结果。那就先把成品放上来,如下图

vim_c_ide oenhan

vim_c_ide oenhan

详细代码参考https://github.com/morphoen/vim,整个代码也是从https://github.com/morphoen/dot-vimrc修改而来,专门针对我需要查看内核代码做的修改,原配置可能更适合前端开发等。安装方法:

sudo apt-get install ctags cscope git
mv ~/.vim ~/.vim.orig
mv ~/.vimrc ~/.vimrc.orig

git clone https://github.com/morphoen/vim.git ~/.vim
ln -s ~/.vim/vimrc ~/.vimrc

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

在vim执行“:BundleInstall”进行插件安装。

安装的插件直接看bundles.vim,根据自己需要进行增删即可。

vimrc内容说一下:

source ~/.vim/bundles.vim
" encoding dectection
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
" enable filetype dectection and ft specific plugin/indent
filetype plugin indent on
" enable syntax hightlight and completion
syntax on
syntax enable
"--------
" Vim UI
"--------
" color scheme
set background=dark
"color solarized
colors Tomorrow-Night-Bright
" highlight current line
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
set cursorline cursorcolumn
" search
set incsearch
"set highlight 	" conflict with highlight current line
set ignorecase
set smartcase
" editor settings
set history=1000
set nocompatible
set nofoldenable												  " disable folding"
set confirm													   " prompt when existing from an unsaved file
set backspace=indent,eol,start									" More powerful backspacing
set t_Co=256													  " Explicitly tell vim that the terminal has 256 colors "
set mouse=a													   " use mouse in all modes
set report=0													  " always report number of lines changed				"
set nowrap														" dont wrap lines
set scrolloff=5												   " 5 lines above/below cursor when scrolling
set number														" show line numbers
set showmatch													 " show matching bracket (briefly jump)
set showcmd													   " show typed command in status bar
set title														 " show file in titlebar
set laststatus=2												  " use 2 lines for the status bar
set matchtime=2												   " show matching bracket for 0.2 seconds
set matchpairs+=<:>											   " specially for html
" Default Indentation
set autoindent
set smartindent	 " indent when
set tabstop=4	   " tab width
set softtabstop=4   " backspace
set shiftwidth=4	" indent width
set expandtab	   " expand tab to space
"-----------------
" Plugin settings
"-----------------
let g:indent_guides_auto_colors = 1
let g:indent_guides_start_level=1
let g:indent_guides_guide_size=1
" Rainbow parentheses for Lisp and variants
let g:rbpt_colorpairs = [
  \ ['brown',	   'RoyalBlue3'],
  \ ['Darkblue',	'SeaGreen3'],
  \ ['darkgray',	'DarkOrchid3'],
  \ ['darkgreen',   'firebrick3'],
  \ ['darkcyan',	'RoyalBlue3'],
  \ ['darkred',	 'SeaGreen3'],
  \ ['darkmagenta', 'DarkOrchid3'],
  \ ['brown',	   'firebrick3'],
  \ ['gray',		'RoyalBlue3'],
  \ ['black',	   'SeaGreen3'],
  \ ['darkmagenta', 'DarkOrchid3'],
  \ ['Darkblue',	'firebrick3'],
  \ ['darkgreen',   'RoyalBlue3'],
  \ ['darkcyan',	'SeaGreen3'],
  \ ['darkred',	 'DarkOrchid3'],
  \ ['red',		 'firebrick3'],
  \ ]
let g:rbpt_max = 16
" tabbar
let g:Tb_MaxSize = 2
let g:Tb_TabWrap = 1
hi Tb_Normal guifg=white ctermfg=white
hi Tb_Changed guifg=green ctermfg=green
hi Tb_VisibleNormal ctermbg=252 ctermfg=235
hi Tb_VisibleChanged guifg=green ctermbg=252 ctermfg=white
" easy-motion
let g:EasyMotion_leader_key = '<Leader>'
" Tagbar
let g:tagbar_left=1
let g:tagbar_width=30
let g:tagbar_autofocus = 1
let g:tagbar_sort = 0
let g:tagbar_compact = 1
" Nerd Tree
let NERDChristmasTree=0
let NERDTreeWinSize=30
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
" let NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$',  '\~$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos = "right"
" nerdcommenter
let NERDSpaceDelims=1
" nmap <D-/> :NERDComToggleComment<cr>
let NERDCompactSexyComs=1
" powerline
"let g:Powerline_symbols = 'fancy'
" NeoComplCache
let g:neocomplcache_enable_at_startup=1
let g:neoComplcache_disableautocomplete=1
"let g:neocomplcache_enable_underbar_completion = 1
"let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_smart_case=1
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
set completeopt-=preview
imap <C-k> <Plug>(neocomplcache_snippets_force_expand)
smap <C-k> <Plug>(neocomplcache_snippets_force_expand)
imap <C-l> <Plug>(neocomplcache_snippets_force_jump)
smap <C-l> <Plug>(neocomplcache_snippets_force_jump)
" Enable omni completion.
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType c setlocal omnifunc=ccomplete#Complete
if !exists('g:neocomplcache_omni_patterns')
  let g:neocomplcache_omni_patterns = {}
endif
let g:neocomplcache_omni_patterns.erlang = '[a-zA-Z]\|:'
" SuperTab
" let g:SuperTabDefultCompletionType='context'
let g:SuperTabDefaultCompletionType = '<C-X><C-U>'
let g:SuperTabRetainCompletionType=2
" ctrlp
set wildignore+=*/tmp/*,*.so,*.o,*.a,*.obj,*.swp,*.zip,*.pyc,*.pyo,*.class,.DS_Store  " MacOSX/Linux
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
" Keybindings for plugin toggle
nnoremap <C-F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
nmap <C-F5> :TagbarToggle<cr>
nmap <C-F6> :NERDTreeToggle<cr>
nmap <F3> :GundoToggle<cr>
nmap <F4> :IndentGuidesToggle<cr>
nmap <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
nmap  <D-/> :
nnoremap <leader>a :Ack
nnoremap <leader>v V`]
"------------------
" Useful Functions
"------------------
" easier navigation between split windows
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
    \ if ! exists("g:leave_my_cursor_position_alone") |
    \	 if line("'\"") > 0 && line ("'\"") <= line("$") |
    \		 exe "normal g'\"" |
    \	 endif |
    \ endif
" w!! to sudo & write a file
cmap w!! %!sudo tee >/dev/null %
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" sublime key bindings
nmap <D-]> >>
nmap <D-[> <<
vmap <D-[> <gv
vmap <D-]> >gv
" eggcache vim
nnoremap ; :
:command W w
:command WQ wq
:command Wq wq
:command Q q
:command Qa qa
:command QA qa
set guifont=Ubuntu\ Mono\ 12
if has('cscope')
  set cscopetag
  set csto=0
  cs add cscope.out
  set cscopeverbose
  "set cscopequickfix=s-,c-,d-,i-,t-,e-
  cnoreabbrev csa cs add
  cnoreabbrev csf cs find
  cnoreabbrev csfs cs find s
  cnoreabbrev csfc cs find c
  cnoreabbrev csfe cs find e
  cnoreabbrev csft cs find t
  cnoreabbrev csfd cs find d
  cnoreabbrev csfi cs find i
  cnoreabbrev csfg cs find g
  cnoreabbrev csk cs kill
  cnoreabbrev csr cs reset
  cnoreabbrev css cs show
  cnoreabbrev csh cs help
  nmap <Tab-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> 
endif

贴上之后发现没啥说的,自己慢慢看吧,主要几个快捷键了解之后就很方便了。

除了我不需要的编译功能,还有cscope的快捷键还没搞好,做好之后再贴上来吧。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多