【原创】我用的vimrc,推荐给大家
vim吧
全部回复
仅看楼主
level 7
haomarlin 楼主
我在公司做linux上的软件开发,目前在用VIM。下面是我为我作的项目配置的vim脚本,大家可以摘取自己想要的。不懂的可以回复。
" set term=linux
set mouse=a
set nocp
set showcmd
set so=5
set laststatus=0
" set gd
bp
rg=/opt/gdb74/bin/cross-gdb
" variables for packages develop
let s:device = "none"
let s:nfsroot = $NFSROOT
let s:devlist = ['pkta', 'pktb', 'pktc', 'pktd', 'pkte', 'pktf', 'pktg']
let s:devopt = ['Select the package name:', '1. pkta', '2. pktb', '3. pktc', '4. pktd', '5. pkte', '6. pktf', '7. pktg']
let s:home = $HOME
let s:workdir = ""
let s:workdir = s:home . "/work/wiretap/firm/sdo/"
" if !isdirectory(s:workdir)
" let s:workdir = s:home . "/workdir"
" endif
let g:shellcmd = ";"
" set list
" set listchars=tab:>-,trail:-
set writebackup
runtime! ftplugin/man.vim
set nrformats-=octal
set ignorecase smartcase
" set nowrapscan
let Tlist_Use_SingleClick = 1
" let Tlist_Auto_Open = 1
set cpt=.,w,b,u,U,i,d,t
if(has("gui_running"))
colorscheme torte
set gfn=Fixedsys\ Excelsior\ 3.01\ 12
let Tlist_Use_SingleClick = 1
let Tlist_Auto_Open = 1
endif
map <Leader>t0 :call Ct()<C-M>
map <Leader>t1 :call Ct0()<C-M>
map <Leader>t2 :call Ct1()<C-M>
map <Leader>t3 :call Ct2()<C-M>
map <Leader>c0 :call Cs()<C-M>
map <Leader>c1 :call Cs0()<C-M>
map <Leader>c2 :call Cs1()<C-M>
let g:miniBufExplUseSingleClick = 1
" let g:miniBufExplVSplit = 25
map <C-PageUp> ^Wh<PageUp>^Wl
map <C-PageDown> ^Wh<PageDown>^Wl
" Syntax highlighting only for vim-enhanced
if has("syntax")
syntax on
endif
" I know it's horrible for a vi master but useful for newbies.
imap <C-a> <Esc>I
imap <C-e> <ESC>A
map <C-Tab> <C-W>w
imap <C-Tab> <C-O><C-W>w
imap <C-Tab> <C-C><C-Tab>
map <kMinus> :cp<C-M>
map - :cp<C-M>
map <kPlus> :cn<C-M>
map + :cn<C-M>
vmap <C-c> "+y
nmap <C-c> "+yy
vmap <C-x> "+d
map <C-b> "+p
" Some macros to manage the buffer of vim
map <F2> :call AutoMake(1)<C-M>
imap <F2> <Esc>:call AutoMake(1)<C-M>
map <F3> :w<C-M>:TlistUpdate<C-M>:TlistSync<C-M>
imap <F3> <Esc>:w<C-M>:TlistUpdate<C-M>:TlistSync<C-M>a
map <F4> :call AutoMake(2)<C-M>
imap <F4> <Esc>:call AutoMake(2)<C-M>
map <F5> :hide bp<C-M>:call AutoMake(0)<C-M>
imap <F5> <Esc>:hide bp<C-M>
map <F6> :hide bn<C-M>:call AutoMake(0)<C-M>
imap <F6> <Esc>:hide bn<C-M>
map <F7> :call CBuffer()<C-M>
map <F8> :call PtagShow()<C-M>
imap <F8> <Esc>:call PtagShow()<C-M>a
2012年12月25日 10点12分 1
level 7
haomarlin 楼主
map <F9> :call AutoShellCmd()<C-M>
map <F10> :w<C-M>:!touch -c -m *.c<C-M>:TlistUpdate<C-M>:TlistSync<C-M>
imap <F10> <Esc>:w<C-M>:!touch -c -m *.c<C-M>:TlistUpdate<C-M>:TlistSync<C-M>a
" map <F9> :call SetupEnv()<C-M>
map <Leader>env :call SetupEnv()<C-M>
map <Leader>dev :call SetupDevice()<C-M>
map <Leader>gdb :call SetupGDB()<C-M>
" imap <F9> <Esc>:call SetupEnv()<C-M>
imap <C-<kPoint>> <C-x><C-o>
imap <C->> <C-x><C-o>
au BufRead *.* call CMap()
au BufRead *.* call AutoMake(0)
au BufReadPost *.c call ReadUndo()
au BufReadPost *.cpp call ReadUndo()
au BufReadPost *.h call ReadUndo()
au BufReadPost *.sh call ReadUndo()
au BufWritePost *.c call WriteUndo()
au BufWritePost *.cpp call WriteUndo()
au BufWritePost *.h call WriteUndo()
au BufWritePost *.sh call WriteUndo()
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>
exec "set path+=" . s:workdir
" Default backspace like normal
set bs=2
" Terminal for 80 char ? so vim can play till 79 char.
"set textwidth=79
" Some options deactivated by default (remove the "no" to enable them)
set nobackup
" set backup
" set nohlsearch
set hlsearch
" set noincsearch
set incsearch
" Always display a status-bar
" set laststatus=2
" Show the position of the cursor
set ruler
" Uncomment this to disable wrap
" set nowrap
" Show matching parentheses
set showmatch
" Make % work with <>
set mps+=<:>
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set guioptions-=T
set ruler
set incsearch
filetype on
"set history=1000
"set background=dark
syntax on
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set guioptions-=T
set vb t_vb=
set nocompatible
"set columns=80
set tabstop=4
set noexpandtab
set number
set ignorecase
set wrapmargin=15
set cindent
set shiftwidth=4
"set hlsearch
"colorscheme desert
let g:ptagStatus = 0
let g:ptagWord = ""
function! PtagShow()
let g:ptagStatus = 1 - g:ptagStatus
let s:word = expand("<cword>")
if s:word != g:ptagWord
2012年12月25日 10点12分 2
level 7
haomarlin 楼主
let g:ptagStatus = 1
endif
let s:aword = match(s:word, '[a-zA-Z_]')
if s:aword < 0
let g:ptagStatus = 0
let g:ptagWord = ""
endif
let ret = taglist("^" . s:word . "$")
if len(ret) <= 0
return
endif
if g:ptagStatus == 1
exec "ptag" s:word
let g:ptagWord = s:word
else
exec "pclose"
endif
endfunction
filetype plugin indent on
set completeopt=longest,menu
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:winManagerWindowLayout='FileExplorer|TagList'
set cscopequickfix=s-,c-,d-,i-,t-,e-
set foldtext=MyFoldText()
function! MyFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
return v:folddashes . sub
endfunction
" config for Gundo
let g:gundo_width = 25
let g:gundo_preview_height = 8
let g:gundo_preview_bottom = 1
let g:gundo_right = 1
let g:gundo_help = 0
" Disable AutoComplPop.
let g:acp_enableAtStartup = 1
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 0
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1
" Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1
" Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
" Define dictionary.
let g:neocomplcache_dictionary_filetype_lists = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplcache_keyword_patterns')
let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
imap (neocomplcache_snippets_expand)
smap (neocomplcache_snippets_expand)
inoremap neocomplcache#undo_completion()
inoremap neocomplcache#complete_common_string()
" SuperTab like snippets behavior.
"imap neocomplcache
#sources#
snippets_complete#expandable() ? "\(neocomplcache_snippets_expand)" : pumvisible() ? "\" : "\"
" Recommended key-mappings.
" : close popup and save indent.
inoremap pumvisible() ? neocomplcache#smart_close_popup() : "\"
" : completion.
inoremap pumvisible() ? "\" : "\"
" , : close popup and delete backword char.
2012年12月25日 10点12分 3
level 7
haomarlin 楼主
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><C-y> neocomplcache#close_popup()
inoremap <expr><C-e> neocomplcache#cancel_popup()
" AutoComplPop like behavior.
"let g:neocomplcache_enable_auto_select = 0
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplcache_enable_auto_select = 1
"let g:neocomplcache_disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
"inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>"
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Enable heavy omni completion.
if !exists('g:neocomplcache_omni_patterns')
let g:neocomplcache_omni_patterns = {}
endif
let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
"autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
let g:neocomplcache_omni_patterns.c = '\%(\.\|->\)\h\w*'
let g:neocomplcache_omni_patterns.cpp = '\h\w*\%(\.\|->\)\h\w*\|\h\w*::'
"Added by haohm
function! Cs()
cs reset
exec "cd " . s:workdir
!cscope-indexer -r
"!cscope -bqR
exec "cs add cscope.out " . s:workdir
cd -
endfunction
function! Cs0()
cs reset
exec "cd " . s:workdir
exec "cs add cscope.out " . s:workdir
cd -
endfunction
function! Cs1()
cd vimtag/linux-2.6.18_pro500/include
cs add cscope.out ~/vimtag/linux-2.6.18_pro500/include
cd -
endfunction
function! Ct()
exec "set tag-=" . s:workdir . "/tags"
exec "cd " . s:workdir
!ctags -R --links=no
exec "silent set tag+=" . s:workdir . "/tags"
cd -
endfunction
function! Ct0()
exec "set tag-=" . s:workdir . "/tags"
exec "cd " . s:workdir
exec "set tag+=" . s:workdir . "/tags"
cd -
endfunction
function! Ct1()
set tag+=~/vimtag/linux-2.6.18_pro500/include/tags
endfunction
function! Ct2()
set tag+=~/vimtag/include/tags
endfunction
function! CheckType()
if &filetype == "c"
call Cs0()
call Ct0()
endif
endfunction
function! CBuffer()
let obufnr = bufnr('%')
bp
let nbufnr = bufnr('%')
if nbufnr != obufnr
exec 'bd' . obufnr
else
exec 'qa'
endif
endfunction
2012年12月25日 10点12分 4
level 7
haomarlin 楼主
function! SetupEnv()
let g:miniBufExplorerMoreThanOne = 0
MiniBufExplorer
exec "Tlist"
if getcwd() == $HOME
exec "NERDTree " . s:workdir
else
exec "NERDTree " . getcwd()
endif
let minibufnr = bufwinnr("MiniBufExplorer")
exec minibufnr . "wincmd w"
exec "wincmd K"
exec "10wincmd -"
let winnr = bufwinnr(1)
exec winnr . "wincmd w"
"au! CursorMoved *.* :TlistSync
endfunction
function! CheckQf()
let qf = getqflist()
for item in qf
if item.valid == 1 && ( match(item.text, "错误") > 0 || match(item.text, "[eE]rror:") > 0 )
return 1
endif
endfor
return 0
endfunction
function! AutoMake(pro)
let filefullname = bufname("%")
let filenamepos = match(filefullname, "\/[^\/]*$")
if filenamepos <= 0
let filenameops = 0
endif
let filename = strpart(filefullname, filenamepos, strlen(filefullname) - filenamepos)
if filenamepos > 0
let filepath = strpart(filefullname, 0, filenamepos)
else
let filepath = "."
endif
exec "cd " . filepath
let filepath = getcwd()
exec "set statusline=". filepath
if a:pro == 0
return
endif
" this should be copied to somewhere
exec "set makeprg=NFSROOT=" . s:nfsroot . "\\ make"
" special automake procedures
for item in s:atmk_group00
if match(filepath, item) >= 0
exec "make"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group01
if match(filepath, item) >= 0
if match(s:device, 'pktf') >= 0
exec "make DEVICE=pktc"
elseif match(s:device 'pktc') >= 0
exec "make DEVICE=pktc"
else
exec "make DEVICE=pktb"
endif
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group02
if match(filepath, item) >= 0
if match(s:device, 'pktd') >= 0
exec "make"
elseif match(s:device, 'pktf') >= 0 || match(s:device, 'pkte') >= 0
exec "make "
else
exec "make "
endif
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group03
2012年12月25日 10点12分 5
level 7
haomarlin 楼主
if match(filepath, item) >= 0
if match(s:device, 'pktg') >= 0
exec "make DEVICE=pktg"
else
exec "make"
endif
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group10
if match(filepath, item) >= 0
if match(s:device, 'pktc') >= 0 || match(s:device, 'pktb') >= 0
exec "make "
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
if match(s:device, 'pktf') >= 0
exec "make DEVICE=pktf"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make DEVICE=pktf install"
return
endif
if match(s:device, 'pkta') >= 0
exec "make DEVICE=pkta"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make DEVICE=pkta install"
return
endif
if match(s:device, 'pktg') >= 0
exec "make DEVICE=pktg"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make DEVICE=pktg install"
return
endif
endif
endfor
for item in s:atmk_group20
if match(filepath, item) >= 0
set makeprg=xmake
exec "make"
exec "set makeprg=NFSROOT=" . s:nfsroot . "\\ make"
if CheckQf() > 0 || a:pro <= 1
return
endif
if match(s:device, 'pktb') >= 0
exec "make install_tddvideo_arm_release"
endif
if match(s:device, 'pktc') >= 0
exec "make install_tddvip_arm_release"
endif
if match(s:device, 'pktf') >= 0
exec "make install_vmssrvext_arm_release"
endif
if match(s:device, 'pktg') >= 0
exec "make install_rta_arm_release"
endif
if match(s:device, 'pkta') >= 0
exec "make install_netbdg_arm_release"
endif
return
endif
endfor
for item in s:atmk_group30
if match(filepath, item) >= 0
exec "make"
2012年12月25日 10点12分 6
level 7
haomarlin 楼主
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group40
if match(filepath, item) >= 0
exec "make"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
return
endif
endfor
for item in s:atmk_group50
if match(filepath, item) >= 0
set makeprg=make
exec "make"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "set makeprg=NFSROOT=" . s:nfsroot . "\\ make"
exec "make install"
return
endif
endfor
for item in s:atmk_group55
if match(filepath, item) >= 0
set makeprg=xmake
exec "make"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "set makeprg=NFSROOT=" . s:nfsroot . "\\ make"
exec "make install"
return
endif
endfor
for item in s:atmk_group60
if match(filepath, item) >= 0
set makeprg=xmake
exec "make"
return
endif
endfor
exec "make"
if CheckQf() > 0 || a:pro <= 1
return
endif
exec "make install"
endfunction
function! SetupDevice()
let sel = inputlist(s:devopt)
if sel <= 0 || sel >= len(s:devopt)
echo "\nInvalid device type selection"
return
endif
let s:device = s:devlist[sel - 1]
echo "\n"
let sel = inputlist(['Change NFSROOT when execute Make install?', '1. Yes', '2. No'])
if sel == 1
let s:nfsroot = $NFSROOT . "_" . s:device
endif
endfunction
function! AutoShellCmd()
exec "silent !" . g:shellcmd
redraw!
endfunction
function! SetupGDB()
silent !echo -e def arminit\\n\\tset confirm off\\n\\tset confirm on\\n\\tset sysroot /opt/gdb74/arm-lib\\n\\tadd-symbol-file /opt/gdb74/arm-lib/lib/ld-2.5.90.so 0x40000000\\nend\\n > ~/.gdbinit 2>/dev/null
redraw!
call ToggleGDB()
call gdb("arminit")
endfunction
function! ReadUndo()
if filereadable('/opt/vim73/undofiles' . expand('%:p'))
silent rundo /opt/vim73/undofiles%:p
endif
endfunc
function! WriteUndo()
let dirname = '/opt/vim73/undofiles' . expand('%:p:h')
if !isdirectory(dirname)
call mkdir(dirname, 'p')
endif
wundo /opt/vim73/undofiles%:p
endfunc
2012年12月25日 10点12分 7
level 10
好多,好乱。建议楼主加注释,然后分类。另外,不要都放这里,有些可以写成ftplugin
2012年12月25日 13点12分 8
level 3
加注释,,直接把vimrc复制来。。。太乱了
2012年12月25日 14点12分 9
level 4
参考
2013年01月09日 11点01分 10
1