Project Explorer,Mini buf expl在VIM中使用

时间:2008-11-14 22:10:36

标签: c++ vim

在VIM中使用项目资源管理器的任何技巧? 如何从项目中的所有文件中搜索?我试过\ g \ G但他们不工作。

如何关闭Project explorer窗口?

我正在使用Project explorer和taglist,当我打开它们时,左侧有两个窗口,这使得非常混乱。是否有可能在视觉工作室中打开右侧的标签列表。

我也在使用mini buf explorer?我知道可以用以下方法关闭bufferes:bd但是如何关闭迷你缓冲区?

如果你们都在使用C ++,请发布你的vimrc ..

我是VIM的新手并且处于学习阶段。你的技巧可能会有所帮助...

1 个答案:

答案 0 :(得分:4)

我经常使用 vim ctags 编写C ++代码。这是我的dot.vimrc:

set backspace=indent,eol,start 
set completeopt=preview,menu
set nocompatible            
set nofoldenable
set novisualbell                
set expandtab
set foldlevel=0
set autowrite
set hlsearch
set showcmd
set showmode
set wildmenu
set pastetoggle=<F12>
set history=500
set mouse=a
set ruler
set cino=l1g0t0p0i0+0:0(0{0
"set ignorecase
set incsearch
set magic
set t_Co=256

" omnicppcomplete  
"
let OmniCpp_GlobalScopeSearch   = 1
let OmniCpp_NamespaceSearch     = 2 
let OmniCpp_DisplayMode         = 1 
let OmniCpp_ShowScopeInAbbr     = 0
let OmniCpp_ShowPrototypeInAbbr = 1
let OmniCpp_ShowAccess          = 1
let OmniCpp_MayCompleteDot      = 1
let OmniCpp_MayCompleteArrow    = 1
let OmniCpp_MayCompleteScope    = 0 
let OmniCpp_SelectFirstItem     = 0
let OmniCpp_LocalSearchDecl     = 0
let OmniCpp_DefaultNamespaces   = ['std', '_GLIBCXX_STD', 'tr1', '__gnu_cxx', 'generic', 'more']

" other features
"
if v:version >= 600
        filetype plugin on
        filetype indent on
else
        filetype on
endif

if has("syntax")
        syntax on
endif

" automatic commands 
"
if has("autocmd")
        autocmd BufEnter *    set cindent comments=""
        autocmd FileType make set noexpandtab shiftwidth=8
        autocmd FileType c    map <buffer> <leader><space> :w<cr>:!gcc %<cr> -I . -Wall
        autocmd FileType c    call UserSpaceMode() | set shiftwidth=4 ts=4 iskeyword=a-z,A-Z,48-57,_
        autocmd FileType cpp  call UserSpaceMode() | set shiftwidth=4 ts=4 iskeyword=a-z,A-Z,48-57,_,:
        autocmd FileType cpp  map <buffer> <leader><space> :w<cr>:!g++ %<cr> -I . -Wall  
        autocmd FileType cpp  map <C-]> :exe "tj /.*" . expand("<cword>") . "$" <cr>
endif

" tab code completition with SuperTab
"
if version >= 700
        let g:SuperTabDefaultCompletionType = "<C-X><C-P>"
        highlight   clear
        highlight   Pmenu         ctermfg=0 ctermbg=2 gui=NONE
        highlight   PmenuSel      ctermfg=0 ctermbg=7 gui=NONE
        highlight   PmenuSbar     ctermfg=7 ctermbg=0 gui=NONE
        highlight   PmenuThumb    ctermfg=0 ctermbg=7 gui=NONE

        if has("gui_running")
                colorscheme inkpot
        else
                colorscheme default
        endif

endif


" ctags options
"
let my_err_counter = 0
let my_space_counter  = 1 
let my_extra_path     = [ '/usr/include/c++/4.3/' ]
let my_ctags_options  = [ '--languages=C,C++', '--c++-kinds=+p',   
                        \'--fields=+iaS', '--extra=+q', '-I __THROW,__NTH,__wur,__warnattr,
                        \__nonnull,__attribute_malloc__,__attribute_pure__,__attribute_used__,
                        \__attribute_noinline__,__attribute_deprecated__,__attribute_format_arg__,
                        \__attribute_format_strfmon__,__attribute_warn_unused_result__,__always_inline,
                        \__extern_inline,__extension__,__restrict' ]

" ctags functions
"
function! UpdateExtraTags()
        execute ":!ctags " . join(g:my_ctags_options,' ') . " -V -R -f ~/.vim/extratags " . join(g:my_extra_path, ' ')    
        echohl StatusLine | echo "Extra tags updated" | echohl None
endfunction

function! UpdateTags()
        execute ":!ctags -V -R " . join(g:my_ctags_options, ' ')   
        echohl StatusLine | echo "C/C++ tag updated" | echohl None
endfunction

" user/kernel-space tags switcher
"
function! UserSpaceMode()
        set tags=tags,~/.vim/extratags
endfunction
function! KernelSpaceMode()
        set tags=tags,/usr/src/linux/tags
endfunction

function! SwitchSpaceMode() 
    let g:my_space_counter+=1
    if (g:my_space_counter%2)
            call UserSpaceMode()
            echohl StatusLine | echo "userspace-tags mode" | echohl None
    else
            call KernelSpaceMode()
            echohl StatusLine | echo "kernelspace-tags mode" | echohl None
    endif
endfunction

function! SwitchErrMode()
    let g:my_err_counter+=1
    if (g:my_err_counter%2)
            copen 
    else
            cclose
    endif
endfunction

" diff the current buffer with its unmodified version in the filesystem 
"
function! s:DiffWithSaved()
  let filetype=&ft
  diffthis
  vnew | r # | normal! 1Gdd
  diffthis
  exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()

" insert c/c++ gates
"
function! s:insert_gates()
  let gatename = "_" . substitute(toupper(expand("%:t")), "[\\.-]", "_", "g") . "_"
  execute "normal! ggI#ifndef " . gatename
  execute "normal! o#define " . gatename . " "
  execute "normal! Go#endif /* " . gatename . " */"
  normal! kk
endfunction

" insert namepsace c++ 
"
function! s:insert_namespace()
  call inputsave()
  let ns =  inputdialog("namespace? ")
  call inputrestore()
  execute "normal! Anamespace " . ns . " { "
  execute "normal! o} // namespace " . ns 
  normal! kk
endfunction

" insert c++ class 
"
function! s:insert_class()
  call inputsave()
  let classname =  inputdialog("ClassName? ")
  call inputrestore()
  execute "normal! iclass " . classname 
  execute "normal! o{ "  
  execute "normal! opublic:"
  execute "normal! o" . classname . "()"
  execute "normal! o{}"
  execute "normal! o"
  execute "normal! o~" . classname . "()"
  execute "normal! o{}"
  execute "normal! o"
  execute "normal! oprivate:"
  execute "normal! o"
  execute "normal! o// non-copyable idiom"
  execute "normal! o" . classname . "(const " . classname "&);"
  execute "normal! o" . classname . " & operator=(const " . classname "&);"
  execute "normal! o"
  execute "normal! o};"
endfunction

" insert c++ value class 
"
function! s:insert_value_class()
  call inputsave()
  let classname =  inputdialog("ValueClassName? ")
  call inputrestore()
  execute "normal! iclass " . classname 
  execute "normal! o{ "  
  execute "normal! opublic:"
  execute "normal! o" . classname . "()"
  execute "normal! o{ /* implementation */ }"
  execute "normal! o"
  execute "normal! o~" . classname . "()"
  execute "normal! o{ /* implementation */ }"
  execute "normal! o"  
  execute "normal! o" . classname . "(const " . classname "&)"
  execute "normal! o{ /* implementation */ }"
  execute "normal! o"  
  execute "normal! o" . classname . " & operator=(const " . classname "& value)"
  execute "normal! o{ /* implementation: " . classname . " tmp(value); swap(value); */"
  execute "normal! oreturn *this;" 
  execute "normal! o}"
  execute "normal! o"  
  execute "normal! o" . classname . " & operator@=(const " . classname . " &)"
  execute "normal! o{ /* implementation */" 
  execute "normal! oreturn *this;" 
  execute "normal! o}" 
  execute "normal! o"
  execute "normal! ofriend const " . classname . " operator@(" . classname . " lhs, const " . classname . " &rhs)"
  execute "normal! o{ return lhs@=rhs; }" 
  execute "normal! o"
  execute "normal! o" . classname . " & operator++()"
  execute "normal! o{ /* implementation*/" 
  execute "normal! oreturn *this;" 
  execute "normal! o}"
  execute "normal! o"  
  execute "normal! o" . classname . " & operator++(int)"
  execute "normal! o{"
  execute "normal! o" . classname . " tmp(*this);"
  execute "normal! o++(*this);" 
  execute "normal! oreturn tmp;" 
  execute "normal! o}"
  execute "normal! o"
  execute "normal! oprivate:"
  execute "normal! o"
  execute "normal! o};"
endfunction

"autocmd BufNewFile *.{h,hpp} call <SID>insert_gates()

" abbreviate...
"
iab intmain int<cr>main(int argc, char *argv[])<cr>{<cr>return 0;<cr>}<cr>
iab #i #include <><Left>
iab #d #define
iab __P __PRETTY_FUNCTION__
iab __F __FUNCTION__

" set mapleader
"
let mapleader = ","

" keyboard mappig
"
map <F1>  :call <SID>insert_gates() <cr> 
map <F2>  :call <SID>insert_namespace() <cr> 
map <F3>  :call <SID>insert_class() <cr> 
map <F4>  :call <SID>insert_value_class() <cr> 

map <F5>  :call SwitchSpaceMode() <cr>
map <F7>  :make<cr>
map <F8>  :call SwitchErrMode() <cr>

map <F9>  :call UpdateTags() <cr> 
map <F10> :call UpdateExtraTags() <cr> 
map <F11> :call <SID>DiffWithSaved() <cr>

map <leader>e :e ~/.vimrc<cr>       " edit vimrc 
map <leader>u :source ~/.vimrc<cr>  " update vimrc

map <tab> :tabnext<cr>
map <S-tab> :tabprevious<cr>

" plugins
"
runtime! ftplugin/man.vim
runtime! ftplugin/gzip.vim
runtime! ftplugin/taglist.vim

快乐的编码! : - )