tags:

views:

1137

answers:

1

Any tricks for using project explorer in VIM? How can I search from all files in project? I tried \g \G but they dont work .

How to toggle on off Project explorer window?

I am using Project explorer and taglist and when I open both then there are two windows on left side ,this makes very much cluttered .Is it possible when to open taglist on right side as done in visual studio.

I am also using mini buf explorer ? I know bufferes can be closed with :bd but how to close mini buffers??

If you guys work on C++ , please post your vimrc ..

I am new to VIM and in learning phase. Your tricks may help...

+3  A: 

I regulary code C++ with vim and ctags. Here's my 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 funtions
"
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

Happy coding! :-)

Nicola Bonelli