vim 常用插件
.vimrc 文件
将 .vimrc 文件复制到 ~ 目录下就可以了。
" vim common cmd
" ci[ delete character between [] and enter insert mode.
" ci( delete character between () and enter insert mode.
" ci{ delete character between {}and enter insert mode.
" ci< delete character between <> and enter insert mode.
" note: ci-->ca, it will delete [],(),{},<>.
" if you just want to select the character, use ci-->vi instead.
"
" gg=G format the code.
"global function
function! GetSys()
if has("win16") || has("win32") || has("win64") || has("win95")
return "windows"
elseif has("unix")
return "linux"
endif
endfunction
" for taglist
""""""""""""""""""""""""""""""""""""""""""
":Tlist open taglist
":TlistToggle open taglist
let Tlist_Ctags_Cmd='/usr/bin/ctags'
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
set tags+=/usr/include/tags
set tags+=/usr/local/include/tags
set tags+=/root/unpv13e/tags
set tags+=/root/NetVol1/working-branch/tags
set tags+=/root/git/JCL/branches/working-branch/tags
nnoremap <silent><F4> :TlistToggle<CR>
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
if exists("tags")
set tags+=./tags
endif
"title
""""""""""""""""""""""""""""""""""""""""""
set title
set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%)
set titlestring=%F
"status bar
""""""""""""""""""""""""""""""""""""""""""
set laststatus=2 "(default is 1, will not display status bar. set to 2 will display status bar)
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
set statusline=
set statusline+=%-3.3n\ "buffer number
set statusline+=%f\ "filename
set statusline+=%h%m%r%w "status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] "filetype
set statusline+=%= "right align remainder
set statusline+=0x%-8B "character value
set statusline+=%-14(%l,%c%V%) "line, character
set statusline+=%<%P "file position
"cmd bar
""""""""""""""""""""""""""""""""""""""""""
set showcmd " Show (partial) command in status line.
set showmode
set cmdheight=1
"fold
""""""""""""""""""""""""""""""""""""""""""
set foldenable
set foldmethod=syntax "index, expr, marker, syntax, diff
"set foldclose=all
" use space to folden, zo:open the fold, zc:fold.
nnoremap <space> @=((foldclosed(line( '.' ))<0) ? 'zc' : 'zo')<CR>
set foldopen-=search "don't open folds when I search
set foldopen-=undo "don't open folds when I undo
set foldlevel=100 "don't folds when I open the file
"set foldcolumn=1 "set the fold column width
"Linebreak on 500 characters
""""""""""""""""""""""""""""""""""""""""""
set tw=500
set lbr
set fo+=mB "support for chinese.
"common
""""""""""""""""""""""""""""""""""""""""""
if has("syntax")
syntax enable
syntax on
endif
if has('mouse')
set mouse=a " Enable mouse usage (all modes)
endif
filetype plugin on
filetype indent on
set autoread "set to auto read when a file is changed from the outside.
set ambiwidth=double "for some unicode special character.
set whichwrap=b,s,<,>,[,]
set nocompatible "close vi compatible mode
set backspace=indent,eol,start
set history=100
set cursorline "current line will have a underline.
set hlsearch " hight light search
set number
set ruler "display cursor position in the right corner of the vim window
set magic "set magic on, for regular expression
set noautochdir
set nocompatible " Use Vim defaults
set ignorecase " ignore case
set incsearch " display when you still typing
set wrapscan " stop the scan at the end of file
set wrap
set hidden
set vb t_vb= "close the voice when cmd error.
" Show autocomplete menus.
set wildmenu
" Minimal number of screen lines to keep above and below the cursor.
"set scrolloff=999
"map
""""""""""""""""""""""""""""""""""""""""""
"Command Normal Visual OperatorPending InsertOnly CommandLine
":map y y y
":nmap y
":vmap y
":omap y
":map! y y
":imap y
":cmap y
""""""""""""""""""""""""""""""""""""""""""
":h key-notation to see vim help document.
":map to list all key map.
"<Esc> stand for Escape
"<CR> stand for Enter
"<Space> <Tab>
"<C-Esc> stand for Ctrl-Esc
"<C-G> stand for Ctrl-G
"<C-LeftMouse> Ctrl+mouse left clicked.
"<S-F1> stand for Shift-F1
"<M-key> or <A-key> stand for Alt
""""""""""""""""""""""""""""""""""""""""""
"<F1>, <F11> can't be use
"<F1> is the ubuntu help dialog.
"<F11> is the ubuntu console maximum
"set mapleader
let mapleader="," "mapleader default is '/', <leader> is mapleader.
let g:mapleader=","
"use ,s to source .vimrc
map <silent> <leader>s :source ~/.vimrc<CR>
"use ,e to open .vimrc
map <silent> <leader>e :e ~/.vimrc<CR>
"auto source .vimrc after edit .vimrc
autocmd! bufwritepost .vimrc source ~/.vimrc
"use , to remove highlight search
nmap <silent> <leader><CR> :noh<CR>
nmap <leader>w :w!<cr>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
map <leader>v :vsplit<CR>
map <C-A> ggvGY
map! <C-A> <Esc>ggvGY
map <F2> <Esc>:tabnew<CR>
map <C-P> :tabprev<CR>
map <C-N> :tabnext<CR>
map <C-C> :tabclose<CR>
"nnoremap <F3> :g/^\s*$/d<CR> "this will delete all blank line in file.
"map <C-H> :hide<CR>
"map <C-J> :tn<CR>
"map <C-K> :tp<CR>
"map <C-L> :cd .<CR>
map \p i(<Esc>ea)<Esc>
map \c i{<Esc>ea}<Esc>
map \n :nohlsearch<CR>
nmap <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
map <F5> :set ts=4<CR>:set expandtab<CR>:%retab!<CR>
map <C-F5> :set ts=4<CR>:set noexpandtab<CR>:%retab!<CR>
"if no !, just replace first TAB of each line.
map <F7> ggO/*<CR><Esc>0d$I * Copyright(c) 2016 ShaXian MDGSF.<CR><Esc>0d$I *<CR><Esc>0d$I * Authored by MDGSF on:<Esc>:read !date <CR>kJ$a<CR><Esc>0d$I *<CR><Esc>0d$I * @desc:<CR><Esc>0d$I *<CR><Esc>0d$I * @history:<CR><Esc>0d$I */<Esc>
map <F8> O/*<CR><Esc>0d$I * Copyright(c) 2016 ShaXian MDGSF.<CR><Esc>0d$I * Authored by MDGSF on:<Esc>:read !date <CR>kJ$a<CR><Esc>0d$I * Function:<CR><Esc>0d$I * @param<CR><Esc>0d$I * @return:<CR><Esc>0d$I */<Esc>
"indent
""""""""""""""""""""""""""""""""""""""""""
"set expandtab "tab will auto changed to blank space, (Ctrl+V+tab will input real tab), Makefile command need tab.
set smartindent " (set si)
set smarttab
set tabstop=4 " tab stop (set ts=4)
set shiftwidth=4 " shift width
set softtabstop=4
set autoindent " auto indent (set ai)
set wrap "Wrap lines
"auto complete
":inoremap ( ()<Esc>i
":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {}<Esc>i
":inoremap } <c-r>=ClosePair('}')<CR>
":inoremap [ []<Esc>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap " ""<Esc>i
":inoremap ' ''<Esc>i
"function! ClosePair(char)
" if getline('.')[col('.') - 1] == a:char
" return "\<Right>"
" else
" return a:char
" endif
"endfunction
"
""open cpp and text at the same time,
""{ will not like you want.
""for c/c++
"function! InitC()
" set cindent
" set cino=:0g0t0(sus
" inoremap { {<CR>}<Esc>ko
"endfunction
"autocmd! Filetype c,cpp,h,hpp :call InitC()
"au! BufNewFile,BufRead c,cpp,h,hpp :call InitC()
"for text
autocmd! FileType text :call InitText()
function! InitText()
setlocal textwidth=78
"inoremap { {}<Esc>i
endfunction
"for html
au FileType html setlocal autoindent indentexpr=
""""""""""""""""""""""""""""""""""""""""""
" BufExplorer
""""""""""""""""""""""""""""""""""""""""""
",bv
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
let g:bufExplorerSortBy="mru"
let g:bufExplorerSplitRight=0
let g:bufExplorerSplitVertical=1
let g:bufExplorerSplitVertSize=30
let g:bufExplorerUseCurrentWindow=1
autocmd BufWinEnter \[Buf\ List\] setl nonumber
""""""""""""""""""""""""""""""""""""""""""
" Nerd tree
""""""""""""""""""""""""""""""""""""""""""
map <F10> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
""""""""""""""""""""""""""""""""""""""""""
" a.vim
""""""""""""""""""""""""""""""""""""""""""
":A switches to the header file corresponding to the current file being edited (or vise versa)
":AS splits and switches
":AV vertical splits and switches
":AT new tab and switches
":AN cycles through matches
":IH switches to file under cursor
":IHS splits and switches
":IHV vertical splits and switches
":IHT new tab and switches
":IHN cycles through matches
"<Leader>ih switches to file under cursor
"<Leader>is switches to the alternate file of file under cursor (e.g. on <foo.h> switches to foo.cpp)
"<Leader>ihn cycles through matches
nnoremap ;z :A<CR>
"for windows and gui
if (has("win32"))
if (has("gui_running"))
set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI
set guifontwide=NSimSun:h9:cGB2312
"hide gui
"set guioptions-=m "remove menu bar
set guioptions-=T "remove tool bar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=l "remove left-hand scroll bar
set guioptions-=L "remove left-hand scroll bar even if there is a vertical split
set guioptions-=b "remove bottom scroll bar
endif
else
if (has("gui_running"))
set guifont=Bitstream\ Vera\ Sans\ Mono\ 9
endif
endif
if GetSys() == "windows"
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5
set encoding=utf-8
set langmenu=zh_CN.UTF-8
language message zh_CN.UTF-8
set nowrap
colo torte
endif
function! ToggleSyntax()
if(exists("g:syntax_on"))
syntax off
else
syntax enable
endif
endfunction
nmap <silent> ;s :call ToggleSyntax()<CR>
function! CapitalizeCenterAndMoveDown()
s/\<./\u&/g
center
+1
endfunction
nmap <silent> ;c :call CapitalizeCenterAndMoveDown()<CR>
function! CurrentLineLength()
let len = strlen(getline("."))
return len
endfunction
""""""""""""""""""""""""""""""""""""""""""
":help vim-script-intro
":help keycodes
":help functions
":help function-list
"let count = 1
"let s:count = 1 s: means count is a local variable.