[原]贴个自个用的vimrc

2190阅读 0评论2015-03-22 Garfield_Trump
分类:LINUX

  1. "~/.vimrc (configuration file for vim only)

  2. " Encoding related
  3. set fileencodings=utf-8,gb2312,gbk,gb18030
  4. set termencoding=utf-8

  5. """""""""""""""""""""""""""""""""""""""""""""""""""""""
  6. " vundle begin
  7. """""""""""""""""""""""""""""""""""""""""""""""""""""""
  8. filetype off                " required!

  9. set rtp+=~/.vim/bundle/vundle/
  10. call vundle#rc()

  11. " let Vundle manage Vundle
  12. Bundle 'gmarik/vundle'

  13. " vim-scripts repos

  14. "  Improved C++ STL syntax highlighting
  15. Bundle 'STL-improved'

  16. " Displays tags in a window, ordered by class etc, i used it instead of taglist
  17. Bundle 'majutsushi/tagbar'

  18. " recommend fetch it from which support c and cpp
  19. Bundle 'tczengming/autoload_cscope.vim'

  20. Bundle 'CmdlineComplete'
  21. Bundle 'xptemplate'

  22. "  Ultimate auto completion system for Vim
  23. Bundle 'neocomplcache'

  24. "Bundle 'Rip-Rip/clang_complete'
  25. "Bundle 'osyo-manga/neocomplcache-clang_complete'

  26. Bundle 'genutils'
  27. Bundle 'lookupfile'

  28. " Fuzzy file, buffer, mru, tag, ... finder with regexp support.
  29. Bundle 'kien/ctrlp.vim'

  30. " Fast file navigation
  31. Bundle 'wincent/Command-T'

  32. " Preview the definition of variables or functions in a preview window
  33. Bundle 'autopreview'

  34. " Echo the function declaration in the command line for C/C++
  35. Bundle 'echofunc.vim'

  36. Bundle 'grep.vim'
  37. Bundle 'a.vim'
  38. Bundle 'The-NERD-Commenter'
  39. Bundle 'The-NERD-tree'

  40. " Under linux need exec 'dos2unix ~/.vim/bundle/QFixToggle/plugin/qfixtoggle.vim'
  41. Bundle 'QFixToggle'

  42. Bundle 'Color-Sampler-Pack'
  43. Bundle 'altercation/vim-colors-solarized'
  44. Bundle 'txt.vim'
  45. Bundle 'mru.vim'
  46. Bundle 'YankRing.vim'
  47. Bundle 'tpope/vim-surround.git'
  48. Bundle 'DoxygenToolkit.vim'
  49. Bundle 'tczengming/headerGatesAdd.vim'
  50. Bundle 'ShowMarks'
  51. Bundle 'Lokaltog/vim-powerline'

  52. " Deal with pairs of punctuations such as (), [], {}, and so on
  53. Bundle 'kana/vim-smartinput'

  54. " non github repos
  55. " ...
  56. filetype plugin indent on   " required! 
  57. """""""""""""""""""""""""""""""""""""""""""""""""""""""
  58. " vundle end
  59. """""""""""""""""""""""""""""""""""""""""""""""""""""""

  60. " solarized theme
  61. set t_Co=256                " Explicitly tell vim that the terminal supports 256 colors, need before setting the colorscheme
  62. let g:solarized_termcolors=256
  63. colorscheme solarized
  64. set background=dark

  65. " Enable syntax highlighting
  66. syntax on

  67. set number
  68. set autochdir               " 自动切换当前目录为当前文件所在的目录

  69. " Set to auto read when a file is changed from the outside
  70. set autoread

  71. " 下面两行改变备份文件存放路径
  72. set backupdir=~/.vim/backup
  73. set directory=~/.vim/backup

  74. " vim-powerline
  75. set laststatus=2            " always have status-line'
  76. let g:Powerline_symbols = 'fancy'
  77. "set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ [ascii:%b\ hex:0x\%02.2B]\ [%{(&fenc\ ==\ \"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %=%l/%L,%v\ %p%%

  78. " allow backspacing over everything in insert mode
  79. set backspace=indent,eol,start

  80. " 光标到达行尾或者行首时,特定键继续移动转至下一行或上一行
  81. set whichwrap+=b,s,<,>,[,]

  82. " Tab related
  83. set shiftwidth=4
  84. set tabstop=4
  85. set softtabstop=4
  86. set expandtab               " Use spaces instead of tabs
  87.                         
  88. set list
  89. set listchars=tab:\|\ ,     " 显示Tab符,使用一高亮竖线代替

  90. " Indent related
  91. "
  92. " g0 类的public顶格写
  93. " :0 将 case 标号放在 switch() 缩进位置之后的 N 个字符处
  94. " N-s namespace 下顶格
  95. " (0  条件语句多个条件在不同行时下一行与上一行对齐
  96. set cinoptions=g0,:0,N-s,(0

  97. set autoindent      " always set autoindenting on
  98. set smartindent

  99. set mps+=<:>        " 让<>可以使用%跳转
  100. set hid             " allow to change buffer without saving 
  101. set shortmess=atI   " shortens messages to avoid 'press a key' prompt 
  102. set lazyredraw      " do not redraw while executing macros (much faster)

  103. " Set Number format to null(default is octal) , when press CTRL-A on number
  104. " like 007, it would not become 010
  105. set nf=

  106. " In Visual Block Mode, cursor can be positioned where there is no actual character
  107. set ve=block

  108. set ignorecase  " Set search/replace pattern to ignore case 
  109. set smartcase   " Set smartcase mode on, If there is upper case character in the search patern, the 'ignorecase' option will be override.
  110. set showcmd     " display incomplete commands
  111. set incsearch   " do incremental searching
  112. set hlsearch    " highlight search
  113. set magic       " Enable magic matching
  114. set showmatch   " show matching paren
  115. set wildmenu    " 增强模式中的命令行自动完成操作
  116. "set mouse=a    " Enable mouse usage (all modes) in terminals

  117. " showmarks setting
  118. let showmarks_enable = 0            " disable showmarks when vim startup
  119. let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  120. let showmarks_ignore_type = "hqm"   " help, Quickfix, non-modifiable

  121. " NERDTree options
  122. " Auto change the root directory
  123. let NERDTreeChDirMode=2
  124. let g:NERDTreeWinSize = 23

  125. " Tagbar options
  126. let g:tagbar_width = 30

  127. let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
  128. let g:DoxygenToolkit_blockFooter="--------------------------------------------------------------------------"
  129. let g:DoxygenToolkit_authorName="zengming@jyxtec.com" 
  130. let g:DoxygenToolkit_versionString="0.1.00"
  131. let g:DoxygenToolkit_briefTag_funcName="yes"
  132. autocmd BufNewFile *.{h,hpp,c,cpp} DoxAuthor 

  133. " Switching between buffers. 
  134. nnoremap h
  135. nnoremap j
  136. nnoremap k
  137. nnoremap l
  138. inoremap h
  139. inoremap j
  140. inoremap k
  141. inoremap l

  142. " Set Up and Down non-linewise
  143. noremap gk
  144. noremap gj

  145. " use Meta key(Windows:Alt) to move cursor in insert mode. 
  146. " Note: if system install "Lingoes Translator", 
  147. "   you will need change/disabled hot key. 
  148. noremap!
  149. noremap!
  150. noremap!
  151. noremap!

  152. "/ : 把单个单词放入搜索或者命令行

  153. " open ctags entries in a new tab
  154. nnoremap T

  155. set pastetoggle=
  156. nnoremap :Grep
  157. nnoremap :Rgrep
  158. nnoremap :AutoPreviewToggle
  159. inoremap :AutoPreviewToggle

  160. " --lookupfile--
  161. "  script to generate filenametags
  162. "  #!/bin/sh
  163. "  # generate tag file for lookupfile plugin, use absolute path
  164. "  echo -e "!_TAG_FILE_SORTED\t2\t/2=foldcase/" > filenametags
  165. "  find `pwd` -not -regex '.*\.\(png\|gif\)' -type f -printf "%f\t%p\t1\n" | \
  166. "      sort -f >> filenametags 
  167. "      
  168. let g:LookupFile_MinPatLength = 2               "最少输入2个字符才开始查找 
  169. let g:LookupFile_PreserveLastPattern = 0        "不保存上次查找的字符串 
  170. "let g:LookupFile_PreservePatternHistory = 1     "保存查找历史 
  171. let g:LookupFile_AlwaysAcceptFirst = 1          "回车打开第一个匹配项目 
  172. let g:LookupFile_AllowNewFiles = 0              "不允许创建不存在的文件 
  173. if filereadable("./filenametags")                "设置tag文件的名字
  174. let g:LookupFile_TagExpr ='"./filenametags"'
  175. endif

  176. "ctrlp
  177. let g:ctrlp_user_command = 'find %s -type f'

  178. set tags=tags;

  179. " -- cscope --
  180. let g:autocscope_menus=0
  181. " Use quickfix window to show cscope results
  182. set cscopequickfix=s-,c-,d-,i-,t-,e-

  183. "'csto' 被设为 0,cscope 数据库先 被搜索,搜索失败的情况下在搜索标签文件 
  184. "设定了 'cscopetag',这样所有的 :tag 命令就会实际上调用 :cstag。这包括 :tag、Ctrl-] 及 vim -t。
  185. "结果是一般的 tag 命令不仅搜索由 ctags 产生的标签文 件,同时也搜索 cscope 数据库,但是好像有bug,二者共存时有的无法搜索
  186. if has("cscope") 
  187.     set csprg=/usr/bin/cscope
  188.     " Use both cscope and ctag
  189.     set cscopetag
  190.     " Show msg when cscope db added
  191.     set cscopeverbose
  192.     " Use cscope for definition search first
  193.     set cscopetagorder=0
  194. endif

  195. nmap s :cs find s =expand("")
  196. nmap g :cs find g =expand("")
  197. nmap c :cs find c =expand("")
  198. nmap t :cs find t =expand("")
  199. nmap e :cs find e =expand("")
  200. nmap f :cs find f =expand("")
  201. nmap i :cs find i ^=expand("")$
  202. nmap d :cs find d =expand("")

  203. " 解决cscope与tag共存时ctrl+]有时不正常的bug
  204. nmap :tj =expand("")

  205. " Disable AutoComplPop.
  206. let g:acp_enableAtStartup = 0
  207. " Use neocomplcache.
  208. let g:neocomplcache_enable_at_startup = 1
  209. " Use smartcase.
  210. let g:neocomplcache_enable_smart_case = 1
  211. " Use camel case completion.
  212. let g:neocomplcache_enable_camel_case_completion = 1
  213. " Use underbar completion.
  214. let g:neocomplcache_enable_underbar_completion = 1
  215. " Set minimum syntax keyword length.
  216. let g:neocomplcache_min_syntax_length = 3
  217. let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
  218. let g:neocomplcache_enable_ignore_case = 0

  219. " Define dictionary.
  220. let g:neocomplcache_dictionary_filetype_lists = {
  221.     \ 'default' : '',
  222.     \ 'vimshell' : $HOME.'/.vimshell_hist',
  223.     \ 'scheme' : $HOME.'/.gosh_completions'
  224.     \ }

  225. " Define keyword.
  226. if !exists('g:neocomplcache_keyword_patterns')
  227.   let g:neocomplcache_keyword_patterns = {}
  228. endif
  229. let g:neocomplcache_keyword_patterns['default'] = '\h\w*'

  230. " Recommended key-mappings.
  231. " : close popup and save indent.
  232. inoremap  neocomplcache#smart_close_popup() . "\"
  233. " : completion.
  234. "inoremap  pumvisible() ? "\" : "\"
  235. " , : close popup and delete backword char.
  236. inoremap neocomplcache#smart_close_popup()."\"
  237. inoremap neocomplcache#smart_close_popup()."\"
  238. inoremap  neocomplcache#close_popup()
  239. inoremap  neocomplcache#cancel_popup()

  240. " use neocomplcache & clang_complete
  241. " neocomplcache option
  242. "let g:neocomplcache_force_overwrite_completefunc=1
  243. " clang_complete option
  244. "let g:clang_complete_auto=1

  245. "Fast remove highlight search
  246. nmap :noh

  247. " 每行超过80个的字符用下划线标示
  248. au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/

  249. " 超过80个的字符高亮
  250. "au BufWinEnter * let w:m1=matchadd('Search', '\%<88v.\%>81v', -1)
  251. "au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)

  252. "高亮显示txt 需要txt.vim
  253. au BufRead,BufNewFile * setfiletype txt

  254. " Restore the last quit position when open file. 
  255.  autocmd BufReadPost * 
  256.     \ if line("'\"") > 0 && line("'\"") <= line("$") | 
  257.      \     exe "normal g'\"" | 
  258.      \ endif

  259. " 自动更新最后修改时间
  260. function! AutoUpdateTheLastUpdateInfo()
  261.     let s:original_pos = getpos(".")
  262.     let s:regexp = "^\\s*\\([#\\\"\\*]\\|\\/\\/\\)\\s\\?[lL]ast \\([uU]pdate\\|[cC]hange\\):"
  263.     let s:lu = search(s:regexp)
  264.     if s:lu != 0
  265.         let s:update_str = matchstr(getline(s:lu), s:regexp)
  266.         call setline(s:lu, s:update_str . strftime("%Y-%m-%d %H:%M:%S", localtime()))
  267.         call setpos(".", s:original_pos)
  268.     endif
  269. endfunction
  270. autocmd BufWritePost *.{h,hpp,c,cpp} call AutoUpdateTheLastUpdateInfo()
  271. autocmd BufNewFile *.{h,hpp,c,cpp} exec 'call append(0, "\/\/ Last Update:" . strftime("%Y-%m-%d %H:%M:%S", localtime()))'

  272. function! ToggleNERDTreeAndTagbar()
  273.     let w:jumpbacktohere = 1

  274.     " Detect which plugins are open
  275.     if exists('t:NERDTreeBufName')
  276.         let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
  277.     else
  278.         let nerdtree_open = 0
  279.     endif
  280.     let tagbar_open = bufwinnr('__Tagbar__') != -1

  281.     " Perform the appropriate action
  282.     if nerdtree_open && tagbar_open
  283.         NERDTreeClose
  284.         TagbarClose
  285.     elseif nerdtree_open
  286.         TagbarOpen
  287.     elseif tagbar_open
  288.         NERDTree
  289.     else
  290.         NERDTree
  291.         TagbarOpen
  292.     endif

  293.     " Jump back to the original window
  294.     for window in range(1, winnr('$'))
  295.         execute window . 'wincmd w'
  296.         if exists('w:jumpbacktohere')
  297.             unlet w:jumpbacktohere
  298.             break
  299.         endif
  300.     endfor
  301. endfunction

  302. nmap :call ToggleNERDTreeAndTagbar()

已经放到github上了,最新的可到git上查看


希望能给大家做一个参考。插件用bundle (也有人叫vundle)管理的,推荐大家使用bundle,插件安装升级很方便

只要一个vimrc

先安装bundle

git clone ~/.vim/bundle/vundle

然后可下载我的.vimrc替换你的.vimrc 步骤如下:

git clone       

下载后用myvim/myvimrc替换你的.vimrc (可自行修改其内容)

然后在vim中执行

:BundleInstall    就可以自动地安装插件

:BundleInstall! 则是自动更新插件,不用再手动去网上一个个下最新包了。
缷载插件  :BundleClean


推一些插件吧
功能                       插件
在.c/.cpp  与.h间快速切换. a.vim
变量或者函数跳转.        ctags  cscope
输入时提示       neocomplcache
打开某文件时自动插入数据     headerGatesAdd.vim   新建.h文件时自行插入防头重复包含的代码   自个写着玩 
注释与取消注释快速切换.  The-NERD-Commenter
doxygen风格快速注释   DoxygenToolkit.vim
高亮   丰富的配色方案   配对符()[]"" ''等不匹配时会高亮提示
查找 变量 文件       /xxvar   lookupfile ctrlp.vim  
查看函数原型        autopreview    echofunc.vim
显示最近打开过的文件    mru.vim    
丰富的状态栏   vim-powerline   
列出当前文件中的所有宏,全局变量, 函数名等       TagList 不过本人更喜欢tagbar 
记录增删       就算退出编辑器, 还能还原已经修改过的文件, 方便得复制还原   YankRing.vim
%在配符对如()[]""等间跳转       matchit.vim
写标签语言的利器             surround.vim
其他的插件像玩游戏,画表格等不再一一描述
表述可能有些不清, 如需更多资料可上vim官网查阅

最后上个部分效果图:

上一篇:2个分析input event事件的开源工具evtest,getevent
下一篇:linux Coredump系列之一:coredump的产生以及原因分析