VIM配置文件vimrc

VIM配置文件vimrc


Ubuntu 默认情况下只安装tiny-vim , 只要运行 sudo apt-get install vim 安装完整的vim就好了


.vimrc 下载

[python]  view plain copy print ?
  1. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  2. " 
  3. " Author: sunboy_2050 
  4. " Version: 1.0 
  5. " Last Change: 2011-11-11 11:11:11 
  6. " http://blog.csdn.net/sunboy_2050 
  7. " 
  8. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  9.   
  10. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  11. " General 
  12. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  13. "Get out of VI's compatible mode..  
  14. set nocompatible  
  15.   
  16. " Platform  
  17. function! MySys()  
  18.   return "linux"  
  19. endfunction  
  20.   
  21. "Sets how many lines of history VIM har to remember  
  22. set history=400  
  23.   
  24. " Chinese  
  25. if MySys() == "windows"  
  26.    "set encoding=utf-8  
  27.    "set langmenu=zh_CN.UTF-8  
  28.    "language message zh_CN.UTF-8  
  29.    "set fileencodings=ucs-bom,utf-8,gb18030,cp936,big5,euc-jp,euc-kr,latin1  
  30. endif  
  31.   
  32. "Enable filetype plugin  
  33. filetype plugin on  
  34. filetype indent on  
  35.   
  36. "Set to auto read when a file is changed from the outside  
  37. set autoread  
  38.   
  39. "Have the mouse enabled all the time:  
  40. set mouse=a  
  41.   
  42. "Set mapleader  
  43. let mapleader = ","  
  44. let g:mapleader = ","  
  45.   
  46. "Fast saving  
  47. nmap <silent> <leader>ww :w<cr>  
  48. nmap <silent> <leader>wf :w!<cr>  
  49.   
  50. "Fast quiting  
  51. nmap <silent> <leader>qw :wq<cr>  
  52. nmap <silent> <leader>qf :q!<cr>  
  53. nmap <silent> <leader>qq :q<cr>  
  54. nmap <silent> <leader>qa :qa<cr>  
  55.   
  56. "Fast remove highlight search  
  57. nmap <silent> <leader><cr> :noh<cr>  
  58.   
  59. "Fast redraw  
  60. nmap <silent> <leader>rr :redraw!<cr>  
  61.   
  62. " Switch to buffer according to file name  
  63. function! SwitchToBuf(filename)  
  64.     "let fullfn = substitute(a:filename, "^\\~/", $HOME . "/", "")  
  65.     " find in current tab  
  66.     let bufwinnr = bufwinnr(a:filename)  
  67.     if bufwinnr != -1  
  68.         exec bufwinnr . "wincmd w"  
  69.         return  
  70.     else  
  71.         " find in each tab  
  72.         tabfirst  
  73.         let tab = 1  
  74.         while tab <= tabpagenr("{1}quot;)  
  75.             let bufwinnr = bufwinnr(a:filename)  
  76.             if bufwinnr != -1  
  77.                 exec "normal " . tab . "gt"  
  78.                 exec bufwinnr . "wincmd w"  
  79.                 return  
  80.             endif  
  81.             tabnext  
  82.             let tab = tab + 1  
  83.         endwhile  
  84.         " not exist, new tab  
  85.         exec "tabnew " . a:filename  
  86.     endif  
  87. endfunction  
  88.   
  89. "Fast edit vimrc  
  90. if MySys() == 'linux'  
  91.     "Fast reloading of the .vimrc  
  92.     map <silent> <leader>ss :source ~/.vimrc<cr>  
  93.     "Fast editing of .vimrc  
  94.     map <silent> <leader>ee :call SwitchToBuf("~/.vimrc")<cr>  
  95.     "When .vimrc is edited, reload it  
  96.     autocmd! bufwritepost .vimrc source ~/.vimrc  
  97. elseif MySys() == 'windows'  
  98.     " Set helplang  
  99.     set helplang=cn  
  100.     "Fast reloading of the _vimrc  
  101.     map <silent> <leader>ss :source ~/_vimrc<cr>  
  102.     "Fast editing of _vimrc  
  103.     map <silent> <leader>ee :call SwitchToBuf("~/_vimrc")<cr>  
  104.     "When _vimrc is edited, reload it  
  105.     autocmd! bufwritepost _vimrc source ~/_vimrc  
  106.     "Fast copying from linux  
  107.     func! CopyFromZ()  
  108.       autocmd! bufwritepost _vimrc  
  109.       exec 'split y:/.vimrc'  
  110.       exec 'normal 17G'  
  111.       exec 's/return "linux"/return "windows"/'  
  112.       exec 'w! ~/_vimrc'  
  113.       exec 'normal u'  
  114.       exec 'q'  
  115.     endfunc  
  116.     nnoremap <silent> <leader>uu :call CopyFromZ()<cr>:so ~/_vimrc<cr>  
  117. endif  
  118.   
  119. " For windows version  
  120. if MySys() == 'windows'  
  121.     source $VIMRUNTIME/mswin.vim  
  122.     behave mswin  
  123.   
  124.     set diffexpr=MyDiff()  
  125.     function! MyDiff()  
  126.         let opt = '-a --binary '  
  127.         if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif  
  128.         if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif  
  129.         let arg1 = v:fname_in  
  130.         if arg1 =~ ' ' | let arg1 = '"''"' . arg1 . '"' | endif  
  131.         let arg2 = v:fname_new  
  132.         if arg2 =~ ' ' | let arg2 = '"''"' . arg2 . '"' | endif  
  133.         let arg3 = v:fname_out  
  134.         if arg3 =~ ' ' | let arg3 = '"''"' . arg3 . '"' | endif  
  135.         let eq = ''  
  136.         if $VIMRUNTIME =~ ' '  
  137.             if &sh =~ '\<cmd'  
  138.                 let cmd = '""' . $VIMRUNTIME . '\diff"'  
  139.                 let eq = '"''"' 
  140.             else 
  141.                 let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"' 
  142.             endif 
  143.         else 
  144.             let cmd = $VIMRUNTIME . '\diff' 
  145.         endif 
  146.         silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq 
  147.     endfunction 
  148. endif 
  149.  
  150. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  151. " Colors and Fonts 
  152. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  153.  
  154. "Set font 
  155. "if MySys() == "linux" 
  156. "  set gfn=Monospace\ 11 
  157. "endif 
  158.  
  159. " Avoid clearing hilight definition in plugins 
  160. if !exists("g:vimrc_loaded") 
  161.     "Enable syntax hl 
  162.     syntax enable 
  163.  
  164.     " color scheme 
  165.     if has("gui_running") 
  166.         set guioptions-=T 
  167.         set guioptions-=m 
  168.         set guioptions-=L 
  169.         set guioptions-=r 
  170.         colorscheme darkblue_my 
  171.         "hi normal guibg=#294d4a 
  172.     else 
  173.         "colorscheme desert_my" 
  174.     endif " has 
  175. endif " exists(...) 
  176.  
  177. "Some nice mapping to switch syntax (useful if one mixes different languages in one file) 
  178. map <leader>1 :set syntax=c<cr> 
  179. map <leader>2 :set syntax=xhtml<cr> 
  180. map <leader>3 :set syntax=python<cr> 
  181. map <leader>4 :set ft=javascript<cr> 
  182. map <leader>$ :syntax sync fromstart<cr> 
  183.  
  184. autocmd BufEnter * :syntax sync fromstart 
  185.  
  186. "Highlight current 
  187. "if has("gui_running") 
  188. "  set cursorline 
  189. "  hi cursorline guibg=#333333 
  190. "  hi CursorColumn guibg=#333333 
  191. "endif 
  192.  
  193. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  194. " Fileformats 
  195. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  196. "Favorite filetypes 
  197. set ffs=unix,dos 
  198.  
  199. nmap <leader>fd :se ff=dos<cr> 
  200. nmap <leader>fu :se ff=unix<cr> 
  201.  
  202. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  203. " VIM userinterface 
  204. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  205. "Set 7 lines to the curors - when moving vertical.. 
  206. "set so=7 
  207.  
  208. " Maximum window when GUI running 
  209. if has("gui_running") 
  210.   set lines=9999 
  211.   set columns=9999 
  212. endif 
  213.  
  214. "Turn on WiLd menu 
  215. set wildmenu 
  216.  
  217. "Always show current position 
  218. set ruler 
  219.  
  220. "The commandbar is 2 high 
  221. set cmdheight=2 
  222.  
  223. "Show line number 
  224. set nu 
  225.  
  226. "Do not redraw, when running macros.. lazyredraw 
  227. set lz 
  228.  
  229. "Change buffer - without saving 
  230. "set hid 
  231.  
  232. "Set backspace 
  233. set backspace=eol,start,indent 
  234.  
  235. "Bbackspace and cursor keys wrap to 
  236. "set whichwrap+=<,>,h,l 
  237. set whichwrap+=<,> 
  238.  
  239. "Ignore case when searching 
  240. "set ignorecase 
  241.  
  242. "Include search 
  243. set incsearch 
  244.  
  245. "Highlight search things 
  246. set hlsearch 
  247.  
  248. "Set magic on 
  249. set magic 
  250.  
  251. "No sound on errors. 
  252. set noerrorbells 
  253. set novisualbell 
  254. set t_vb= 
  255.  
  256. "show matching bracets 
  257. "set showmatch 
  258.  
  259. "How many tenths of a second to blink 
  260. "set mat=2 
  261.  
  262.   """""""""""""""""""""""""""""" 
  263.   " Statusline 
  264.   """""""""""""""""""""""""""""" 
  265.   "Always hide the statusline 
  266.   set laststatus=2 
  267.  
  268.   function! CurDir() 
  269.      let curdir = substitute(getcwd(), '/home/easwy/', "~/", "g") 
  270.      return curdir 
  271.   endfunction 
  272.  
  273.   "Format the statusline 
  274.   "set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c 
  275.  
  276.  
  277.  
  278. """""""""""""""""""""""""""""" 
  279. " Visual 
  280. """""""""""""""""""""""""""""" 
  281. " From an idea by Michael Naumann 
  282. function! VisualSearch(direction) range 
  283.   let l:saved_reg = @" 
  284.   execute "normal! vgvy" 
  285.   let l:pattern = escape(@", '\\/.*$^~[]') 
  286.   let l:pattern = substitute(l:pattern, "\n{1}quot;, "", "") 
  287.   if a:direction == 'b' 
  288.     execute "normal ?" . l:pattern . "^M" 
  289.   else 
  290.     execute "normal /" . l:pattern . "^M" 
  291.   endif 
  292.   let @/ = l:pattern 
  293.   let @" = l:saved_reg 
  294. endfunction 
  295.  
  296. "Basically you press * or # to search for the current selection !! Really useful 
  297. vnoremap <silent> * :call VisualSearch('f')<CR> 
  298. vnoremap <silent> # :call VisualSearch('b')<CR> 
  299.  
  300.  
  301. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  302. " Moving around and tabs 
  303. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  304. "Map space to / and c-space to ? 
  305. "map <space> / 
  306. "map <c-space> ? 
  307.  
  308. "Smart way to move btw. windows 
  309. nmap <C-j> <C-W>j 
  310. nmap <C-k> <C-W>k 
  311. nmap <C-h> <C-W>h 
  312. nmap <C-l> <C-W>l 
  313.  
  314. "Actually, the tab does not switch buffers, but my arrows 
  315. "Bclose function can be found in "Buffer related" section 
  316. map <leader>bd :Bclose<cr> 
  317. "map <down> <leader>bd 
  318.  
  319. "Use the arrows to something usefull 
  320. "map <right> :bn<cr> 
  321. "map <left> :bp<cr> 
  322.  
  323. "Tab configuration 
  324. map <leader>tn :tabnew 
  325. map <leader>te :tabedit 
  326. map <leader>tc :tabclose<cr> 
  327. map <leader>tm :tabmove 
  328. try 
  329.   set switchbuf=useopen 
  330.   set stal=1 
  331. catch 
  332. endtry 
  333.  
  334. "Moving fast to front, back and 2 sides ;) 
  335. imap <m-{1}gt; <esc>$a 
  336. imap <m-0> <esc>0i 
  337.  
  338. "Switch to current dir 
  339. map <silent> <leader>cd :cd %:p:h<cr> 
  340.  
  341. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  342. " Parenthesis/bracket expanding 
  343. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  344. vnoremap @1 <esc>`>a)<esc>`<i(<esc> 
  345. ") 
  346. vnoremap @2 <esc>`>a]<esc>`<i[<esc> 
  347. vnoremap @3 <esc>`>a}<esc>`<i{<esc> 
  348. vnoremap @$ <esc>`>a"<esc>`<i"<esc> 
  349. vnoremap @q <esc>`>a'<esc>`<i'<esc> 
  350. vnoremap @w <esc>`>a"<esc>`<i"<esc> 
  351.  
  352. "Map auto complete of (, ", ', [ 
  353. inoremap @1 ()<esc>:let leavechar=")"<cr>i 
  354. inoremap @2 []<esc>:let leavechar="]"<cr>i 
  355. inoremap @3 {}<esc>:let leavechar="}"<cr>i 
  356. inoremap @4 {<esc>o}<esc>:let leavechar="}"<cr>O 
  357. inoremap @q ''<esc>:let leavechar="'"<cr>i 
  358. inoremap @w ""<esc>:let leavechar='"'<cr>i  
  359. "au BufNewFile,BufRead *.\(vim\)\@! inoremap " ""<esc>:let leavechar='"'<cr>i  
  360. "au BufNewFile,BufRead *.\(txt\)\@! inoremap ' ''<esc>:let leavechar="'"<cr>i  
  361.   
  362. "imap <m-l> <esc>:exec "normal f" . leavechar<cr>a  
  363. "imap <d-l> <esc>:exec "normal f" . leavechar<cr>a  
  364.   
  365.   
  366. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  367. " General Abbrevs 
  368. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  369. "My information  
  370. iab xdate <c-r>=strftime("%c")<cr>  
  371. iab xname Easwy Yang  
  372.   
  373.   
  374. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  375. " Editing mappings etc. 
  376. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  377.   
  378. func! DeleteTrailingWS()  
  379.   exe "normal mz"  
  380.   %s/\s\+$//ge  
  381.   nohl  
  382.   exe "normal `z"  
  383. endfunc  
  384.   
  385. " do not automaticlly remove trailing whitespace  
  386. "autocmd BufWrite *.[ch] :call DeleteTrailingWS()  
  387. "autocmd BufWrite *.cc :call DeleteTrailingWS()  
  388. "autocmd BufWrite *.txt :call DeleteTrailingWS()  
  389. nmap <silent> <leader>ws :call DeleteTrailingWS()<cr>:w<cr>  
  390. "nmap <silent> <leader>ws! :call DeleteTrailingWS()<cr>:w!<cr>  
  391.   
  392. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  393. " Command-line config 
  394. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  395. "Bash like  
  396. cnoremap <C-A>    <Home>  
  397. cnoremap <C-E>    <End>  
  398. cnoremap <C-K>    <C-U>  
  399.   
  400. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  401. " Buffer realted 
  402. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  403. "Open a dummy buffer for paste  
  404. map <leader>es :tabnew<cr>:setl buftype=nofile<cr>  
  405. if MySys() == "linux"  
  406. map <leader>ec :tabnew ~/tmp/scratch.txt<cr>  
  407. else  
  408. map <leader>ec :tabnew $TEMP/scratch.txt<cr>  
  409. endif  
  410.   
  411. "Restore cursor to file position in previous editing session  
  412. set viminfo='10,\"100,:20,n~/.viminfo  
  413. au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("{1}quot;)|exe("norm '\"")|else|exe "norm {1}quot;|endif|endif  
  414.   
  415. " Don't close window, when deleting a buffer  
  416. command! Bclose call <SID>BufcloseCloseIt()  
  417.   
  418. function! <SID>BufcloseCloseIt()  
  419.    let l:currentBufNum = bufnr("%")  
  420.    let l:alternateBufNum = bufnr("#")  
  421.   
  422.    if buflisted(l:alternateBufNum)  
  423.      buffer #  
  424.    else  
  425.      bnext  
  426.    endif  
  427.   
  428.    if bufnr("%") == l:currentBufNum  
  429.      new  
  430.    endif  
  431.   
  432.    if buflisted(l:currentBufNum)  
  433.      execute("bdelete! ".l:currentBufNum)  
  434.    endif  
  435. endfunction  
  436.   
  437. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  438. " Session options 
  439. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  440. set sessionoptions-=curdir  
  441. set sessionoptions+=sesdir  
  442.   
  443. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  444. " Files and backups 
  445. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  446. "Turn backup off  
  447. set nobackup  
  448. set nowb  
  449. "set noswapfile  
  450.   
  451.   
  452. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  453. " Folding 
  454. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  455. "Enable folding, I find it very useful  
  456. "set fen  
  457. "set fdl=0  
  458. nmap <silent> <leader>zo zO  
  459. vmap <silent> <leader>zo zO  
  460.   
  461.   
  462. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  463. " Text options 
  464. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  465. set expandtab  
  466. set shiftwidth=4  
  467.   
  468. map <leader>t2 :set shiftwidth=2<cr>  
  469. map <leader>t4 :set shiftwidth=4<cr>  
  470. au FileType html,python,vim,javascript setl shiftwidth=2  
  471. "au FileType html,python,vim,javascript setl tabstop=2  
  472. au FileType java,c setl shiftwidth=4  
  473. "au FileType java setl tabstop=4  
  474. au FileType txt setl lbr  
  475. au FileType txt setl tw=78  
  476.   
  477. set smarttab  
  478. "set lbr  
  479. "set tw=78  
  480.   
  481.    """"""""""""""""""""""""""""""  
  482.    " Indent  
  483.    """"""""""""""""""""""""""""""  
  484.    "Auto indent  
  485.    set ai  
  486.   
  487.    "Smart indet  
  488.    set si  
  489.   
  490.    "C-style indeting  
  491.    set cindent  
  492.   
  493.    "Wrap lines  
  494.    set wrap  
  495.   
  496.   
  497. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  498. " Spell checking 
  499. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  500. map <leader>sn ]s  
  501. map <leader>sp [s  
  502. map <leader>sa zg  
  503. map <leader>s? z=  
  504.   
  505. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  506. " Complete 
  507. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  508. " options  
  509. set completeopt=menu  
  510. set complete-=u  
  511. set complete-=i  
  512.   
  513. " mapping  
  514. inoremap <expr> <CR>       pumvisible()?"\<C-Y>":"\<CR>"  
  515. inoremap <expr> <C-J>      pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"  
  516. inoremap <expr> <C-K>      pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"  
  517. inoremap <expr> <C-U>      pumvisible()?"\<C-E>":"\<C-U>"  
  518. inoremap <C-]>             <C-X><C-]>  
  519. inoremap <C-F>             <C-X><C-F>  
  520. inoremap <C-D>             <C-X><C-D>  
  521. inoremap <C-L>             <C-X><C-L>  
  522.   
  523. " Enable syntax  
  524. if has("autocmd") && exists("+omnifunc")  
  525.   autocmd Filetype *  
  526.         \if &omnifunc == "" |  
  527.         \  setlocal omnifunc=syntaxcomplete#Complete |  
  528.         \endif  
  529. endif  
  530.   
  531. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  532. " cscope setting 
  533. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  534. if has("cscope")  
  535.   if MySys() == "linux"  
  536.     set csprg=/usr/bin/cscope  
  537.   else  
  538.     set csprg=cscope  
  539.   endif  
  540.   set csto=1  
  541.   set cst  
  542.   set nocsverb  
  543.   " add any database in current directory  
  544.   if filereadable("cscope.out")  
  545.       cs add cscope.out  
  546.   endif  
  547.   set csverb  
  548. endif  
  549.   
  550. nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>  
  551. nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
  552. nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>  
  553. nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>  
  554. nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>  
  555. nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>  
  556. nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>{1}lt;CR>  
  557. nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>  
  558.   
  559. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  560. " Plugin configuration 
  561. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  562.    """"""""""""""""""""""""""""""  
  563.    " Super Tab  
  564.    """"""""""""""""""""""""""""""  
  565.    "let g:SuperTabDefaultCompletionType = "<C-X><C-O>"  
  566.    let g:SuperTabDefaultCompletionType = "<C-P>"  
  567.   
  568.    """"""""""""""""""""""""""""""  
  569.    " yank ring setting  
  570.    """"""""""""""""""""""""""""""  
  571.    map <leader>yr :YRShow<cr>  
  572.   
  573.    """"""""""""""""""""""""""""""  
  574.    " file explorer setting  
  575.    """"""""""""""""""""""""""""""  
  576.    "Split vertically  
  577.    let g:explVertical=1  
  578.   
  579.    "Window size  
  580.    let g:explWinSize=35  
  581.   
  582.    let g:explSplitLeft=1  
  583.    let g:explSplitBelow=1  
  584.   
  585.    "Hide some files  
  586.    let g:explHideFiles='^\.,.*\.class$,.*\.swp$,.*\.pyc$,.*\.swo$,\.DS_Store  
[python]  view plain copy print ?
  1. "Hide the help thing..  
  2.    let g:explDetailedHelp=0  
  3.   
  4.   
  5.   
  6.   
  7.    """"""""""""""""""""""""""""""  
  8.    " minibuffer setting  
  9.    """"""""""""""""""""""""""""""  
  10.    let loaded_minibufexplorer = 1         " *** Disable minibuffer plugin  
  11.    let g:miniBufExplorerMoreThanOne = 2   " Display when more than 2 buffers  
  12.    let g:miniBufExplSplitToEdge = 1       " Always at top  
  13.    let g:miniBufExplMaxSize = 3           " The max height is 3 lines  
  14.    let g:miniBufExplMapWindowNavVim = 1   " map CTRL-[hjkl]  
  15.    let g:miniBufExplUseSingleClick = 1    " select by single click  
  16.    let g:miniBufExplModSelTarget = 1      " Dont change to unmodified buffer  
  17.    let g:miniBufExplForceSyntaxEnable = 1 " force syntax on  
  18.    "let g:miniBufExplVSplit = 25  
  19.    "let g:miniBufExplSplitBelow = 0  
  20.   
  21.   
  22.    autocmd BufRead,BufNew :call UMiniBufExplorer  
  23.   
  24.   
  25.    """"""""""""""""""""""""""""""  
  26.    " bufexplorer setting  
  27.    """"""""""""""""""""""""""""""  
  28.    let g:bufExplorerDefaultHelp=1       " Do not show default help.  
  29.    let g:bufExplorerShowRelativePath=1  " Show relative paths.  
  30.    let g:bufExplorerSortBy='mru'        " Sort by most recently used.  
  31.    let g:bufExplorerSplitRight=0        " Split left.  
  32.    let g:bufExplorerSplitVertical=1     " Split vertically.  
  33.    let g:bufExplorerSplitVertSize = 30  " Split width  
  34.    let g:bufExplorerUseCurrentWindow=1  " Open in new window.  
  35.    let g:bufExplorerMaxHeight=13        " Max height  
  36.   
  37.   
  38.    """"""""""""""""""""""""""""""  
  39.    " taglist setting  
  40.    """"""""""""""""""""""""""""""  
  41.    if MySys() == "windows"  
  42.      let Tlist_Ctags_Cmd = 'ctags'  
  43.    elseif MySys() == "linux"  
  44.      let Tlist_Ctags_Cmd = '/usr/bin/ctags'  
  45.    endif  
  46.    let Tlist_Show_One_File = 1  
  47.    let Tlist_Exit_OnlyWindow = 1  
  48.    let Tlist_Use_Right_Window = 1  
  49.    nmap <silent> <leader>tl :Tlist<cr>  
  50.   
  51.   
  52.    """"""""""""""""""""""""""""""  
  53.    " winmanager setting  
  54.    """"""""""""""""""""""""""""""  
  55.    let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"  
  56.    let g:winManagerWidth = 30  
  57.    let g:defaultExplorer = 0  
  58.    nmap <C-W><C-F> :FirstExplorerWindow<cr>  
  59.    nmap <C-W><C-B> :BottomExplorerWindow<cr>  
  60.    nmap <silent> <leader>wm :WMToggle<cr>  
  61.    autocmd BufWinEnter \[Buf\ List\] setl nonumber  
  62.   
  63.   
  64.    """"""""""""""""""""""""""""""  
  65.    " netrw setting  
  66.    """"""""""""""""""""""""""""""  
  67.    let g:netrw_winsize = 30  
  68.    nmap <silent> <leader>fe :Sexplore!<cr>  
  69.   
  70.   
  71.    """"""""""""""""""""""""""""""  
  72.    " LaTeX Suite things  
  73.    """"""""""""""""""""""""""""""  
  74.    set grepprg=grep\ -nH\ $*  
  75.    let g:Tex_DefaultTargetFormat="pdf"  
  76.    let g:Tex_ViewRule_pdf='xpdf'  
  77.   
  78.   
  79.    "Bindings  
  80.    autocmd FileType tex map <silent><leader><space> :w!<cr> :silent! call Tex_RunLaTeX()<cr>  
  81.   
  82.   
  83.    "Auto complete some things ;)  
  84.    autocmd FileType tex inoremap $i \indent  
  85.    autocmd FileType tex inoremap $* \cdot  
  86.    autocmd FileType tex inoremap $i \item  
  87.    autocmd FileType tex inoremap $m \[<cr>\]<esc>O  
  88.   
  89.   
  90.   
  91.   
  92.    """"""""""""""""""""""""""""""  
  93.    " lookupfile setting  
  94.    """"""""""""""""""""""""""""""  
  95.    let g:LookupFile_MinPatLength = 2  
  96.    let g:LookupFile_PreserveLastPattern = 0  
  97.    let g:LookupFile_PreservePatternHistory = 0  
  98.    let g:LookupFile_AlwaysAcceptFirst = 1  
  99.    let g:LookupFile_AllowNewFiles = 0  
  100.    if filereadable("./filenametags")  
  101.        let g:LookupFile_TagExpr = '"./filenametags"'  
  102.    endif  
  103.    nmap <silent> <leader>lk <Plug>LookupFile<cr>  
  104.    nmap <silent> <leader>ll :LUBufs<cr>  
  105.    nmap <silent> <leader>lw :LUWalk<cr>  
  106.   
  107.   
  108.    " lookup file with ignore case  
  109.    function! LookupFile_IgnoreCaseFunc(pattern)  
  110.        let _tags = &tags  
  111.        try  
  112.            let &tags = eval(g:LookupFile_TagExpr)  
  113.            let newpattern = '\c' . a:pattern  
  114.            let tags = taglist(newpattern)  
  115.        catch  
  116.            echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE  
  117.            return ""  
  118.        finally  
  119.            let &tags = _tags  
  120.        endtry  
  121.   
  122.   
  123.        " Show the matches for what is typed so far.  
  124.        let files = map(tags, 'v:val["filename"]')  
  125.        return files  
  126.    endfunction  
  127.    let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'  
  128.   
  129.   
  130.    """"""""""""""""""""""""""""""  
  131.    " markbrowser setting  
  132.    """"""""""""""""""""""""""""""  
  133.    nmap <silent> <leader>mk :MarksBrowser<cr>  
  134.   
  135.   
  136.    """"""""""""""""""""""""""""""  
  137.    " showmarks setting  
  138.    """"""""""""""""""""""""""""""  
  139.    " Enable ShowMarks  
  140.    let showmarks_enable = 1  
  141.    " Show which marks  
  142.    let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"  
  143.    " Ignore help, quickfix, non-modifiable buffers  
  144.    let showmarks_ignore_type = "hqm"  
  145.    " Hilight lower & upper marks  
  146.    let showmarks_hlline_lower = 1  
  147.    let showmarks_hlline_upper = 1  
  148.   
  149.   
  150.    """"""""""""""""""""""""""""""  
  151.    " mark setting  
  152.    """"""""""""""""""""""""""""""  
  153.    nmap <silent> <leader>hl <Plug>MarkSet  
  154.    vmap <silent> <leader>hl <Plug>MarkSet  
  155.    nmap <silent> <leader>hh <Plug>MarkClear  
  156.    vmap <silent> <leader>hh <Plug>MarkClear  
  157.    nmap <silent> <leader>hr <Plug>MarkRegex  
  158.    vmap <silent> <leader>hr <Plug>MarkRegex  
  159.   
  160.   
  161.    """"""""""""""""""""""""""""""  
  162.    " FeralToggleCommentify setting  
  163.    """"""""""""""""""""""""""""""  
  164.    let loaded_feraltogglecommentify = 1  
  165.    "map <silent> <leader>tc :call ToggleCommentify()<CR>j   
  166.    "imap <M-c> <ESC>:call ToggleCommentify()<CR>j   
  167.   
  168.   
  169.    """"""""""""""""""""""""""""""  
  170.    " vimgdb setting  
  171.    """"""""""""""""""""""""""""""  
  172.    let g:vimgdb_debug_file = ""  
  173.    run macros/gdb_mappings.vim  
  174.   
  175.   
  176. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  177. " Filetype generic 
  178. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  179.    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  180.    " Todo 
  181.    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  182.    "au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim  
  183.   
  184.   
  185.    """"""""""""""""""""""""""""""  
  186.    " HTML related  
  187.    """"""""""""""""""""""""""""""  
  188.    " HTML entities - used by xml edit plugin  
  189.    let xml_use_xhtml = 1  
  190.    "let xml_no_auto_nesting = 1  
  191.   
  192.   
  193.    "To HTML  
  194.    let html_use_css = 1  
  195.    let html_number_lines = 0  
  196.    let use_xhtml = 1  
  197.   
  198.   
  199.    """""""""""""""""""""""""""""""  
  200.    " Vim section  
  201.    """""""""""""""""""""""""""""""  
  202.    autocmd FileType vim set nofen  
  203.    autocmd FileType vim map <buffer> <leader><space> :w!<cr>:source %<cr>  
  204.   
  205.   
  206.    """"""""""""""""""""""""""""""  
  207.    " HTML  
  208.    """""""""""""""""""""""""""""""  
  209.    au FileType html set ft=xml  
  210.    au FileType html set syntax=html  
  211.   
  212.   
  213.   
  214.   
  215.    """"""""""""""""""""""""""""""  
  216.    " C/C++  
  217.    """""""""""""""""""""""""""""""  
  218.    autocmd FileType c,cpp  map <buffer> <leader><space> :make<cr>  
  219.    "autocmd FileType c,cpp  setl foldmethod=syntax | setl fen  
  220.   
  221.   
  222. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  223. " MISC 
  224. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  225.    "Quickfix  
  226.    nmap <leader>cn :cn<cr>  
  227.    nmap <leader>cp :cp<cr>  
  228.    nmap <leader>cw :cw 10<cr>  
  229.    "nmap <leader>cc :botright lw 10<cr>  
  230.    "map <c-u> <c-l><c-j>:q<cr>:botright cw 10<cr>  
  231.   
  232.   
  233.    function! s:GetVisualSelection()  
  234.        let save_a = @a  
  235.        silent normal! gv"ay  
  236.        let v = @a  
  237.        let @a = save_a  
  238.        let var = escape(v, '\\/.$*')  
  239.        return var  
  240.    endfunction  
  241.   
  242.   
  243.    " Fast grep  
  244.    nmap <silent> <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>  
  245.    vmap <silent> <leader>lv :lv /<c-r>=<sid>GetVisualSelection()<cr>/ %<cr>:lw<cr>  
  246.   
  247.   
  248.    " Fast diff  
  249.    cmap @vd vertical diffsplit   
  250.    set diffopt+=vertical  
  251.   
  252.   
  253.    "Remove the Windows ^M  
  254.    noremap <Leader>dm mmHmn:%s/<C-V><cr>//ge<cr>'nzt'm  
  255.   
  256.   
  257.    "Paste toggle - when pasting something in, don't indent.  
  258.    set pastetoggle=<F3>  
  259.   
  260.   
  261.    "Remove indenting on empty lines  
  262.    "map <F2> :%s/\s*$//g<cr>:noh<cr>''  
  263.   
  264.   
  265.    "Super paste  
  266.    "inoremap <C-v> <esc>:set paste<cr>mui<C-R>+<esc>mv'uV'v=:set nopaste<cr>  
  267.   
  268.   
  269.    "Fast Ex command  
  270.    nnoremap ; :  
  271.   
  272.   
  273.    "For mark move  
  274.    nnoremap <leader>' '  
  275.   
  276.   
  277.    "Fast copy  
  278.    nnoremap ' "  
  279.   
  280.   
  281.    "A function that inserts links & anchors on a TOhtml export.  
  282.    " Notice:  
  283.    " Syntax used is:  
  284.    " Link  
  285.    " Anchor  
  286.    function! SmartTOHtml()  
  287.     TOhtml  
  288.     try  
  289.      %s/&quot;\s\+\*&gt; \(.\+\)</" <a href="#\1" style="color: cyan">\1<\/a></g  
  290.      %s/&quot;\(-\|\s\)\+\*&gt; \(.\+\)</" \&nbsp;\&nbsp; <a href="#\2" style="color: cyan;">\2<\/a></g  
  291.      %s/&quot;\s\+=&gt; \(.\+\)</" <a name="\1" style="color: #fff">\1<\/a></g  
  292.     catch  
  293.     endtry  
  294.     exe ":write!"  
  295.     exe ":bd"  
  296.    endfunction  
  297.   
  298.   
  299.   
  300.   
  301. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
  302. " Mark as loaded 
  303. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
  304. let g:vimrc_loaded = 1  


===========================================================================

vimrc配置文件详解

"set encoding=chinese
"set langmenu=zh_CN.UTF-8"
if version >= 603
    set helplang=cn
endif
set langmenu=zh_CN.UTF-8
"set imcmdline "这一句导致字体大小、颜色设置失效
"set guifont=Monospace/ 12
set guifont=DejaVu/ Sans/ Mono/ 12 
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"下一行为语法高亮,彩色的
syntax on

"添加自动缩进
set tabstop=4
set shiftwidth=4
set softtabstop=4
set ai "开启自动缩进
"set expandtab "自动把tab转化为空格
"retab "将已存在的tab都转化为空格
set list   "显示tab和行尾空格
set lcs=tab:+-,trail:- "显示tab为+---和行尾空格(只在输入时才显示)
"折叠python代码
"set foldmethod=indent
"let Tlist_Auto_Open=1 "auto open taglist自动打开taglist
set autoindent "自动缩进?
"添加python字典,实现自动补全(字典目录为~/.vim/pydiction,里面有字典和一个脚本),快捷键:ctrl+n(20080320 ~/.vim/tools/也可以)
if has("autocmd")
autocmd FileType python set complete+=k~/.vim/tools/pydiction
endif
"安F8智能补全
inoremap <F8> <C-x><C-o>

map <F5>:!/usr/bin/python2.5 %

set nobackup    "不自动备份
set nu      "开启行号
"搜索字高亮
set hlsearch
"取消 Vim 对 HTML 标记自动产生的缩进,但打开自动缩进选项
au FileType html setlocal autoindent indentexpr=

" multi-encoding setting
if has("multi_byte")
"set bomb
set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1
" CJK environment detection and corresponding setting
if v:lang =~ "^zh_CN"
    " Use cp936 to support GBK, euc-cn == gb2312
    set encoding=cp936
    set termencoding=cp936
    set fileencoding=cp936
elseif v:lang =~ "^zh_TW"
    " cp950, big5 or euc-tw
    " Are they equal to each other?
    set encoding=big5
    set termencoding=big5
    set fileencoding=big5
elseif v:lang =~ "^ko"
    " Copied from someone's dotfile, untested
    set encoding=euc-kr
    set termencoding=euc-kr
    set fileencoding=euc-kr
elseif v:lang =~ "^ja_JP"
    " Copied from someone's dotfile, untested
    set encoding=euc-jp
    set termencoding=euc-jp
    set fileencoding=euc-jp
endif
" Detect UTF-8 locale, and replace CJK setting if needed
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
    set encoding=utf-8
    set termencoding=utf-8
    set fileencoding=utf-8
endif
else
echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"
endif

*************************************
//
1.tabstop (ts-数值型): 设定文件中制表位占的空格个数,默认是8
   :set ts=4     (表示一个插入一个<Tab>占4个空格位)

2.expandtab (et-布尔型): 插入<Tab>时使用相应数量的空格,而不用制表位,默认关闭
   :set ts=10 et     (此时插入一个tab时,真正插入的是10个空格)
   注: 当'et'打开,要插入实际的制表位,需用CTRL-V<Tab>,win下加载了mswin.vim插件的用CTRL-Q<Tab>

3.softtabstop (sts-数值型): 当插入一个<Tab>时,若'ts'值大于'sts',则此时就插入'sts'值那么多空格;
   而当'ts'值小于'sts',则此时就插入几个制表位(制表位的个数是'sts'整除'ts'之商)
   和几个空格(空格的个数是'sts'整除'ts'之余数),默认是0,表示关闭
   :set ts=8 sts=6   (此时插入一个<Tab>,就会插入6个空格;若连续插入两个<Tab>,则会插入一个制表位和4个空格)
                    在此设置下这样输入: 一个<Tab>,3个空格,一个<Tab>,大家想想实际会输入什么?
   :set ts=3 sts=8   (此时插入一个<Tab>,就会插入2个制表位和2个空格)

4.retab (ret-ex下的命令,前面3个是选项): 把制表位和空格组成的连续序列替换成新的制表位或空格
   格式是   :[range]ret[!] [ts值]   (不是指定range,默认是全文;不指定'ts'值,就用原来的'ts'值)
   
   (1) 当'et'为关闭状态时,retab会尽量把由"制表位和空格组成的连续空白序列"替换成尽可能多的制表位,如:
   有一个连续"空白序列"是由: 3个空格,两个制表位,5个空格组成,这时设置如下命令
   :ret 6    (原来的"空白序列"变为由: 3个制表位,2个空格组成的新的"空白序列")
   (2) 当'et'为开启状态时,retab会把所有的制表位换成当前'ts
   (3) :ret! 命令则会把纯粹由空格组成的"空白序列"强制替换为尽可能多的制表位加空格
   注:retab命令对文本的处理,不会引起视觉上的变化

5.smarttab (sta-布尔型): 它确定行首插入<Tab>时的情况,它跟选项'shiftwidth'(sw)相关联,默认关闭.
   :set sta   (则若行首插入一个<Tab>,会根据'sw'的值来插入"空白序列",其余的地方还是插入一个制表位;
               而这里的"空白序列"是由什么组成,是由'sw','ts'值的相对大小,以及是否开启了'et'决定的.
               若'sw'小于'ts'的值,且'et'是关闭的,则行首插入一个<Tab>就直接插入'sw'值所代表的空格数;
               若'sw'大于'ts'的值,且'et'是关闭的,则行首插入一个<Tab>就插入尽可能多的制表位加空格;
               若'et'是开启的,若行首插入一个<Tab>就直接插入'sw'值所代表的空格数

   注:选项'sw'只用于normal下的左右移动命令: > , >> , < , <<

************************ 说 明 *********************************
*                                                            
* (a) 文中的<Tab>表示动作:敲击键盘上的Tab制表键(位于Q键左边), 
*     而文中的"制表位"表示前面那个动作后的输入;                
* (b) 为了便于制表位和空格的区分,也就是让它们成为"可见"模式:    
*     :set list                                              
*     :set lcs=eol:&,tab<+        
       set list   "显示tab和行尾空格
       set lcs=tab:>-,trail:- "显示tab为---和行尾空格(只在输入时才显示)                           
*     这样每行结尾有字符"&",制表位若是4,则为:<+++ ,             
*     而若制表位是8,则为:<+++++++                         
* (c) <Backspace>在插入模式下可以删除整个'sts'和'sta'下的'sw' 
*     但象normal下"x"这样的命令就只能删除真正的制表位和空格       
==========================================================================
20090123
" 自动补全命令时候使用菜单式匹配列表
set wildmenu
" 允许退格键删除
set backspace=2
" 启用鼠标
set mouse=a
" 文件类型
filetype on
filetype plugin on
filetype indent on
" 设置编码自动识别, 中文引号显示
"set fileencodings=utf-8,cp936,big5,euc-jp,euc-kr,latin1,ucs-bom
set fileencodings=utf-8,gbk,ucs-bom
set ambiwidth=double

" 移动长行
nnoremap <Down> gj
nnoremap <Up> gk

" 让编辑模式可以中文输入法下按:转到命令模式
nnoremap : :

" 高亮
syntax on
" 设置高亮搜索
set hlsearch
" 输入字符串就显示匹配点
set incsearch
" 输入的命令显示出来,看的清楚些。
set showcmd

" 打开当前目录文件列表
map <F3> :e .<CR>

" Taglist
let Tlist_File_Fold_Auto_Close=1
set updatetime=1000
map <F4> :Tlist<CR>

" 按 F8 智能补全
inoremap <F8> <C-x><C-o>

" vim 自动补全 Python 代码
" 来自http://vim.sourceforge.net/scripts/script.php?script_id=850
autocmd FileType python set complete+=k~/.vim/tools/pydiction
autocmd FileType python set shiftwidth=4 tabstop=4 "expandtab "把tab转化为空格
set list
set lcs=tab:+-,trail:-
" 自动使用新文件模板
autocmd BufNewFile *.py 0r ~/.vim/template/simple.py

autocmd FileType html set shiftwidth=4 tabstop=4 expandtab 
autocmd BufNewFile *.html 0r ~/.vim/template/simple.html

"要在命令行上实现 Emacs 风格的编辑操作: >
" 至行首
:cnoremap <C-A>        <Home>
" 后退一个字符
:cnoremap <C-B>        <Left>
" 删除光标所在的字符
:cnoremap <C-D>        <Del>
" 至行尾
:cnoremap <C-E>        <End>
" 前进一个字符
:cnoremap <C-F>        <Right>
" 取回较新的命令行
:cnoremap <C-N>        <Down>
" 取回以前 (较旧的) 命令行
:cnoremap <C-P>        <Up>
" 后退一个单词
:cnoremap <Esc><C-B>    <S-Left>
" 前进一个单词
:cnoremap <Esc><C-F>    <S-Right>

"Format the statusline
"Nice statusbar
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*/ " buffer number
set statusline+=%f/ " file name
set statusline+=%h%1*%m%r%w%0* " flag
set statusline+=[
if v:version >= 600
set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
endif
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
set statusline+=/ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
"set statusline+=%2*0x%-8B/ " current char
set statusline+=0x%-8B/ " current char
set statusline+=%-14.(%l,%c%V%)/ %<%P " offset

 

参考拓展:

vim配置文件vimrc

 

Vim的分屏功能

 

vim encoding and font

 

vim技巧快捷键学习

 

vim实用功能总结

 

VIM编辑代码时的一些技巧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值