Chinaunix首页 | 论坛 | 博客
  • 博客访问: 76528
  • 博文数量: 35
  • 博客积分: 131
  • 博客等级: 入伍新兵
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-11 22:57
文章分类

全部博文(35)

文章存档

2016年(15)

2013年(1)

2012年(6)

2011年(13)

我的朋友

分类:

2011-09-20 18:15:06

原文地址:vimrc配置 作者:WUYING_2010

本文来自:
  1. " .vimrc
  2. " Written by Matt Roper <matt@mattrope.com>
  3. "
  4. " Feel free to use any or all of this file in your own vimrc file.


  5. " Don't use vi compatibility; I want all the new features in Vim
  6. set nocompatible

  7. " Version 6.0-specific stuff
  8. if version >= 600
  9.     syntax enable
  10.     filetype on
  11.     filetype plugin on
  12.     filetype indent on
  13. else
  14.     syntax on
  15. endif
  16. set number
  17. autocmd BufReadPost *
    \ if line("'\"")>0&&line("'\"")<=line("$") |
    \ exe "normal g'\"" |
    \ endif

  18. " Low priority filename suffixes for filename completion {{{
  19. set suffixes-=.h " Don't give .h low priority
  20. set suffixes+=.aux
  21. set suffixes+=.log
  22. set wildignore+=*.dvi
  23. set suffixes+=.bak
  24. set suffixes+=~
  25. set suffixes+=.swp
  26. set suffixes+=.o
  27. set suffixes+=.class
  28. " }}}

  29. set showfulltag " Get function usage help automatically
  30. set showcmd " Show current vim command in status bar
  31. set showmatch " Show matching parentheses/brackets
  32. set showmode " Show current vim mode

  33. set background=dark

  34. set bs=2 " allow backspacing over everything in insert mode
  35. set viminfo='20,\"50 " read/write a .viminfo file, don't store more
  36.                         " than 50 lines of registers
  37. set history=50 " keep 50 lines of command line history
  38. set ruler " show the cursor position all the time
  39. set nohlsearch " don't highlight search matches
  40. set selection=exclusive " don't include character under cursor in selection
  41. set incsearch " incremental (emacs-style) search
  42. set vb t_vb= " kill the beeps! (visible bell)
  43. set wildmenu " use a scrollable menu for filename completions
  44. "set ignorecase " case-insensitive searching

  45. " Indentation / tab replacement stuff
  46. set shiftwidth=4 " > and < move block by 4 spaces in visual mode
  47. set sts=4
  48. set et " expand tabs to spaces
  49. set autoindent " always set autoindenting on

  50. " Move text, but keep highlight
  51. vnoremap > >gv
  52. vnoremap < <gv

  53. " Color Scheme (only if GUI running) {{{
  54. if has("gui_running")
  55.     colorscheme evening
  56. endif
  57. " }}}

  58. " Key mappings {{{

  59. " Allow the . to execute once for each line in visual selection
  60. vnoremap . :normal .

  61. " Make ' function behave like ` usually does and then change ` to replay
  62. " recorded macro a (as if @a was typed). In visual mode, ` (which now acts
  63. " like @a) should function on all selected lines.
  64. noremap ' `
  65. nnoremap ` @a
  66. vnoremap ` :normal @a<CR>

  67. " Make tab perform keyword/tag completion if we're not following whitespace
  68. inoremap =InsertTabWrapper()

  69. " Make F7 spellcheck the buffer
  70. noremap <F7> <Esc>:call IspellCheck()<CR><Esc>

  71. " Programming Keys:
  72. " F9 = Make
  73. " F10 = Next Error
  74. " F11 = Prev Error
  75. inoremap <F9> <Esc>:make<CR>
  76. inoremap <F10> <Esc>:cnext<CR>
  77. inoremap <F11> <Esc>:cprev<CR>
  78. noremap <F9> <Esc>:make<CR>
  79. noremap <F10> <Esc>:cnext<CR>
  80. noremap <F11> <Esc>:cprev<CR>

  81. " Buffer Switching:
  82. " F2 = next buffer
  83. " F3 = previous buffer
  84. " F4 = kill buffer
  85. inoremap <F2> <Esc>:bn<CR>
  86. inoremap <F3> <Esc>:bp<CR>
  87. inoremap <F4> <Esc>:bd<CR>
  88. noremap <F2> <Esc>:bn<CR>
  89. noremap <F3> <Esc>:bp<CR>
  90. noremap <F4> <Esc>:bd<CR>

  91. " Make p in Visual mode replace the selected text with the "" register.
  92. vnoremap p :let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>

  93. " Key mappings }}}

  94. " Autocommands {{{
  95. if has("autocmd")

  96.     " When vim is used in a console window, set the title bar to the
  97.     " name of the buffer being editted.
  98.     if !has("gui_running")
  99.         auto BufEnter * let &titlestring="VIM - ".expand("%:p")
  100.     endif

  101.     " In text and LaTeX files, always limit the width of text to 76
  102.     " characters. Also perform logical wrapping/indenting.
  103.     autocmd BufRead *.txt set tw=76 formatoptions=tcroqn2l
  104.     autocmd BufRead *.tex set tw=76

  105.     " Programming settings {{{
  106.     augroup prog
  107.         au!
  108.         au BufRead *.c,*.cc,*.cpp,*.h,*.java set formatoptions=croql cindent nowrap nofoldenable
  109.         au BufEnter *.java map :w\|:!javac %
  110.         au BufEnter *.c map :w\|:!gcc %
  111.         au BufEnter *.cc,*.cpp map :w\|:!g++ %
  112.         au BufLeave *.java,*.c,*.cc unmap

  113.         " Don't expand tabs to spaces in Makefiles
  114.         au BufEnter [Mm]akefile* set noet
  115.         au BufLeave [Mm]akefile* set et

  116.         " Set up folding for python
  117.         au FileType python set nofoldenable foldmethod=indent
  118.     augroup END
  119.     " }}}


  120.     " Reread configuration of Vim if .vimrc is saved {{{
  121.     augroup VimConfig
  122.         au!
  123.         autocmd BufWritePost ~/.vimrc so ~/.vimrc
  124.         autocmd BufWritePost vimrc so ~/.vimrc
  125.     augroup END
  126.     " }}}


  127. " " C programming auto commands {{{
  128. " augroup cprog
  129. "
  130. "
  131. " " When starting to edit a file:
  132. " " For C and C++ files set formatting of comments and set C-indenting on.
  133. " " For other files switch it off.
  134. " " Don't change the order, it's important that the line with * comes first.
  135. " "autocmd FileType * set formatoptions=tcql nocindent comments&
  136. " "autocmd FileType c,cpp set formatoptions=croql comments=sr:/*,mb:*,el:*/,://
  137. "
  138. " " Automatic "folding" in C code. This is cool.
  139. " "if version >= 600
  140. " " "au FileType c set foldenable foldmethod=indent
  141. " " au FileType c,cpp set nofoldenable foldmethod=syntax
  142. " " au FileType c,cpp syn region Block start="{" end="}" transparent fold
  143. " " "au FileType c syn region Comment start="/\*" end="\*/" fold
  144. " "endif
  145. " augroup END
  146. " " }}}

  147. endif " has("autocmd")
  148. " }}}

  149. " Functions {{{

  150. " IspellCheck() {{{
  151. function! IspellCheck()
  152.     let l:tmpfile = tempname()

  153.     execute "normal:w!" . l:tmpfile . "\<CR>"
  154.     if has("gui_running")
  155.         execute "normal:!xterm -e ispell " . l:tmpfile . "\<CR>"
  156.     else
  157.         execute "normal:! ispell " . l:tmpfile . "\<CR>"
  158.     endif
  159.     execute "normal:%d\<CR>"
  160.     execute "normal:r " . l:tmpfile . "\<CR>"
  161.     execute "normal:1d\<CR>"
  162. endfunction
  163. " IspellCheck }}}

  164. " InsertTabWrapper() {{{
  165. " Tab completion of tags/keywords if not at the beginning of the
  166. " line. Very slick.
  167. function! InsertTabWrapper()
  168.     let col = col('.') - 1
  169.     if !col || getline('.')[col - 1] !~ '\k'
  170.         return "\<tab>"
  171.     else
  172.         return "\<c-p>"
  173.     endif
  174. endfunction
  175. " InsertTabWrapper() }}}
  176. " Functions }}}

  177. " Settings for specific syntax files {{{
  178. let c_gnu=1
  179. let c_comment_strings=1
  180. let c_space_errors=1

  181. "let perl_fold=1 " turn on perl folding capabilities
  182. " }}}

  183. " Modeline {{{
  184. " vim:set ts=4:
  185. " vim600:fdm=marker fdl=0 fdc=3 vb t_vb=:
  186. " }}}

 
阅读(372) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~