VIMRC 構建強大的vim,附帶IDE強大的各種功能

來源:互聯網
上載者:User

標籤:

使用VIM的程式員很多,這裡提供一個VIMRC,提供了很多自動化的功能,比如高亮代碼,自動完成等等。

"setlocal omnifunc=python3complete#Complete" An example for a vimrc file."" Maintainer:Bram Moolenaar <[email protected]>" Last change:2000 Jan 06"" To use it, copy it to"     for Unix and OS/2:  ~/.vimrc"      for Amiga:  s:.vimrc"  for MS-DOS and Win32:  $VIM\_vimrc"for VMS:  sys$login:.vimrc" Use Vim settings, rather then Vi settings (much better!)." This must be first, because it changes other options as a side effect.set nocompatible"let &termencoding=&encoding"set fileencodings=utf-8,gbk,ucs-bom,cp936set bs=2" allow backspacing over everything in insert mode"set ai" always set autoindenting on"set backup" keep a backup fileset viminfo='20,\"50" read/write a .viminfo file, don't store more" than 50 lines of registersset history=50" keep 50 lines of command line historyset ruler" show the cursor position all the timeset nu"set bdir=~/.vimbackupset nowrapset bg=darkset smarttabset expandtabset tabstop=4" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries" let &guioptions = substitute(&guioptions, "t", "", "g")" Don't use Ex mode, use Q for formattingmap Q gq" Make p in Visual mode replace the selected text with the "" register.vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>" Switch syntax highlighting on, when the terminal has colors" Also switch on highlighting the last used search pattern.syntax onif &t_Co > 2 || has("gui_running")syntax onset hlsearchendif" Only do this part when compiled with support for autocommands." if has("autocmd")"   autocmd BufRead *.txt set tw=78fun SetTitle()    call setline(1, "#coding=gbk")    call append(line("."), "import os")    call append(line(".") + 1,  "import sys")    call append(line(".") + 2,  "import argparse")    call append(line(".") + 3,  "import commands")    call append(line(".") + 4,  "import logging")    call append(line(".") + 5,  "")    call append(line(".") + 6,  "logging.basicConfig(level = logging.DEBUG,")    call append(line(".") + 7,  "        format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',")    call append(line(".") + 8,  "        datefmt = '%Y-%m-%d %H:%M:%S',")    call append(line(".") + 9,  "        filename = os.path.basename(__file__) + '.log',")    call append(line(".") + 10, "        filemode = 'a')")    call append(line(".") + 11, "")    call append(line(".") + 12, "def perror_and_exit(message, status = -1):")    call append(line(".") + 13, "    sys.stderr.write(message + '\\n')")    call append(line(".") + 14, "    logging.info(message + 'sys exit')")    call append(line(".") + 15, "    sys.exit(status)")    call append(line(".") + 16, "")    call append(line(".") + 17, "if __name__ == '__main__':")    call append(line(".") + 18, "    ")    call append(line(".") + 19, "   pass")    call cursor(20, 5)endfuncif has("autocmd")    autocmd BufNewFile *.py exec ":call SetTitle()"" In text files, always limit the width of text to 78 charactersautocmd BufRead *.txt set tw=78augroup cprog" Remove all cprog autocommandsau!" When starting to edit a file:"   For C and C++ files set formatting of comments and set C-indenting on."   For other files switch it off."   Don't change the order, it's important that the line with * comes first.autocmd FileType *      set formatoptions=tcql nocindent comments&autocmd FileType c,cpp  set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,://augroup ENDaugroup gzip" Remove all gzip autocommandsau!" Enable editing of gzipped files" set binary mode before reading the fileautocmd BufReadPre,FileReadPre*.gz,*.bz2 set binautocmd BufReadPost,FileReadPost*.gz call GZIP_read("gunzip")autocmd BufReadPost,FileReadPost*.bz2 call GZIP_read("bunzip2")autocmd BufWritePost,FileWritePost*.gz call GZIP_write("gzip")autocmd BufWritePost,FileWritePost*.bz2 call GZIP_write("bzip2")autocmd FileAppendPre*.gz call GZIP_appre("gunzip")autocmd FileAppendPre*.bz2 call GZIP_appre("bunzip2")autocmd FileAppendPost*.gz call GZIP_write("gzip")autocmd FileAppendPost*.bz2 call GZIP_write("bzip2")" After reading compressed file: Uncompress text in buffer with "cmd"fun! GZIP_read(cmd)" set 'cmdheight' to two, to avoid the hit-return promptlet ch_save = &chset ch=3" when filtering the whole buffer, it will become emptylet empty = line("'[") == 1 && line("']") == line("$")let tmp = tempname()let tmpe = tmp . "." . expand("<afile>:e")" write the just read lines to a temp file "'[,']w tmp.gz"execute "'[,']w " . tmpe" uncompress the temp file "!gunzip tmp.gz"execute "!" . a:cmd . " " . tmpe" delete the compressed lines'[,']d" read in the uncompressed lines "'[-1r tmp"set nobinexecute "'[-1r " . tmp" if buffer became empty, delete trailing blank lineif emptynormal Gdd''endif" delete the temp filecall delete(tmp)let &ch = ch_save" When uncompressed the whole buffer, do autocommandsif emptyexecute ":doautocmd BufReadPost " . expand("%:r")endifendfun" After writing compressed file: Compress written file with "cmd"fun! GZIP_write(cmd)if rename(expand("<afile>"), expand("<afile>:r")) == 0execute "!" . a:cmd . " <afile>:r"endifendfun" Before appending to compressed file: Uncompress file with "cmd"fun! GZIP_appre(cmd)execute "!" . a:cmd . " <afile>"call rename(expand("<afile>:r"), expand("<afile>"))endfunaugroup END" This is disabled, because it changes the jumplist.  Can't use CTRL-O to go" back to positions in previous files more than once.if 0" When editing a file, always jump to the last cursor position." This must be after the uncompress commands.autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endifendifendif " has("autocmd")set shiftwidth=4"set cindentset wrapset ts=4set sw=4set showcmdmap <F8> ggVG= <CR>map <F9> :set nonu <CR>map <F10> :set nu <CR>map <F11> :silent! Tlist<CR>map ,, :A<CR>map ,- :AS<CR>map ,= :AV<CR>"omnicppcomplete configset nocpfiletype plugin onfiletype indent onset tags=tags;"set tags+=~/home/work/tags"set tags+=~/install/tags/wbl_tags"set tags+=~/station/tags"set tags+=~/qqcard_publish/tags"set tags+=~/esales_publish/tags"au BufWritePost *.c,*.cpp,*.cc,*.h !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/station/tags ~/station/"au BufWritePost *.c,*.cpp,*.cc,*.h !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/qqcard_publish/tags ~/qqcard_publish/"au BufWritePost *.c,*.cpp,*.cc,*.h !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/esales_publish/tags ~/esales_publish/"au BufWritePost *.c,*.cpp,*.cc,*.h !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>"let OmniCpp_ShowPrototypeInAbbr = 1let g:neocomplcache_enable_at_startup = 1"taglist configlet Tlist_Ctags_Cmd = '/usr/bin/ctags' "設定linux系統中ctags程式的位置let Tlist_Show_One_File = 1 "不同時顯示多個檔案的tag,只顯示當前檔案的let Tlist_Exit_OnlyWindow = 1 "如果taglist視窗是最後一個視窗,則退出vimlet Tlist_Use_Right_Window = 0 "在右側視窗中顯示taglist視窗 "csope"cscope add ~/Cip_esales_related/cscope/cscope.out"nmap <[email protected]>s :cs find s <C-R>=expand("<cword>")<CR><CR>" Only do this part when compiled with support for autocommandsif has("autocmd")  " In text files, always limit the width of text to 78 characters  autocmd BufRead *.txt set tw=78  " When editing a file, always jump to the last cursor position  autocmd BufReadPost *  \ if line("'\"") > 0 && line ("'\"") <= line("$") |  \   exe "normal! g'\"" |  \ endifendif



VIMRC 構建強大的vim,附帶IDE強大的各種功能

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.