Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3360228
  • 博文数量: 258
  • 博客积分: 9440
  • 博客等级: 少将
  • 技术积分: 6998
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-03 10:28
个人简介

-- linux爱好者,业余时间热衷于分析linux内核源码 -- 目前主要研究云计算和虚拟化相关的技术,主要包括libvirt/qemu,openstack,opennebula架构和源码分析。 -- 第五届云计算大会演讲嘉宾 微博:@Marshal-Liu

文章分类

全部博文(258)

文章存档

2016年(1)

2015年(4)

2014年(16)

2013年(22)

2012年(41)

2011年(59)

2010年(40)

2009年(75)

分类: LINUX

2011-05-01 10:28:18

五一假期闲的难受,就把vim和emacs的配置文件重新整理的一遍,贴出来与大家共享,先介绍vim的配置文件。
主要参考某位大牛师弟的配置,修改而成。文中红色标记部分是比较常用的部分。

使用说明:

1. cscope使用说明

;ss ↔ cs find s ;sg ↔ cs find g
;st ↔ cs find t ;sd ↔ cs find d
;sc ↔ cs find c ;sf ↔ cs find f
;si ↔ cs find i ;se ↔ cs find e
命令说明: c: Find functions calling this function
d: Find functions called by this function
e: Find this egrep pattern
f: Find this file
g: Find this definition
i: Find files #including this file
s: Find this C symbol
t: Find assignments to

  1. 常用快捷键

;F: BufExplorer 窗口 ;ffF5: LookupFile窗口

;t: TagList窗口 ;n: NERD Tree窗口

F12:更新tagscscope文件

C-hshift+tab:向前切换buffer C-ntab:向后切换buffer

注意:这里的前后是指buffer打开的先后

;cc:单行注释

;cs: 单行性感注释

;cu: 取消注释


  1. " vimrc by ustc.dylan@gmail.com
  2. " Modified Data: 2011-05-01
  3. let mapleader = ";" " 比较习惯用;作为命令前缀,右手小拇指直接能按到
  4. " 把空格键映射成:
  5. nmap :
  6. " 快捷打开编辑vimrc文件的键盘绑定
  7. map ee :e $HOME/.vimrc
  8. autocmd! bufwritepost *.vimrc source $HOME/.vimrc
  9. " 保存文件
  10. nmap ww :w!
  11. " ^z快速进入shell
  12. nmap :shell
  13. " 判断操作系统
  14. if (has("win32") || has("win64") || has("win32unix"))
  15. let g:isWin = 1
  16. else
  17. let g:isWin = 0
  18. endif
  19. " 判断是终端还是gvim
  20. if has("gui_running")
  21. let g:isGUI = 1
  22. else
  23. let g:isGUI = 0
  24. endif
  25. set nocompatible " 关闭兼容模式
  26. syntax enable " 语法高亮
  27. filetype plugin on " 文件类型插件
  28. filetype indent on
  29. set autoindent
  30. autocmd BufEnter * :syntax sync fromstart
  31. set nu " 显示行号
  32. set showcmd " 显示命令
  33. set lz " 当运行宏时,在命令执行完成之前,不重绘屏幕
  34. set hid " 可以在没有保存的情况下切换buffer
  35. set backspace=eol,start,indent
  36. set whichwrap+=<,>,h,l " 退格键和方向键可以换行
  37. set incsearch " 增量式搜索
  38. set hlsearch " 高亮搜索
  39. set ignorecase " 搜索时忽略大小写
  40. set magic "
  41. set showmatch " 显示匹配的括号
  42. set nobackup " 关闭备份
  43. set nowb
  44. set noswapfile " 不使用swp文件,注意,错误退出后无法恢复
  45. set lbr " 在breakat字符处而不是最后一个字符处断行
  46. set ai " 自动缩进
  47. set si " 智能缩进
  48. set cindent " C/C++风格缩进
  49. set wildmenu
  50. set nofen
  51. set foldenable
  52. set fdl=3
  53. " tab转化为4个字符
  54. set expandtab
  55. set smarttab
  56. set shiftwidth=4
  57. set tabstop=4
  58. " 不使用beep或flash
  59. set vb t_vb=
  60. set background=dark
  61. colorscheme desert
  62. "set t_Co=256
  63. set history=400 " vim记住的历史操作的数量,默认的是20
  64. set autoread " 当文件在外部被修改时,自动重新读取
  65. set mouse=a " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等
  66. "在gvim中高亮当前行
  67. if (g:isGUI)
  68. set cursorline
  69. hi cursorline guibg=#333333
  70. hi CursorColumn guibg=#333333
  71. set guifont=Consolas\ 14
  72. set guifontwide=Consolas\ 14
  73. endif
  74. " 设置字符集编码,默认使用utf8
  75. if (g:isWin)
  76. let &termencoding=&encoding " 通常win下的encoding为cp936
  77. set fileencodings=utf8,cp936,ucs-bom,latin1
  78. else
  79. set encoding=utf8
  80. set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1
  81. endif
  82. " 状态栏
  83. set laststatus=2 " 总是显示状态栏
  84. highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue
  85. " 获取当前路径,将$HOME转化为~
  86. function! CurDir()
  87. let curdir = substitute(getcwd(), $HOME, "~", "g")
  88. return curdir
  89. endfunction
  90. set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\
  91. " 第80列往后加下划线
  92. "au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)
  93. " 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用
  94. function! VisualSearch(direction) range
  95. let l:saved_reg = @"
  96. execute "normal! vgvy"
  97. let l:pattern = escape(@", '\\/.*$^~[]')
  98. let l:pattern = substitute(l:pattern, "\n$", "", "")
  99. if a:direction == 'b'
  100. execute "normal ?" . l:pattern . ""
  101. else
  102. execute "normal /" . l:pattern . ""
  103. endif
  104. let @/ = l:pattern
  105. let @" = l:saved_reg
  106. endfunction
  107. " 用 */# 向 前/后 搜索光标下的单词
  108. vnoremap * :call VisualSearch('f')
  109. vnoremap # :call VisualSearch('b')
  110. " 在文件名上按gf时,在新的tab中打开
  111. "map gf :tabnew
  112. " 用c-j,k在buffer之间切换
  113. nn :bn
  114. nn :bp
  115. nn :bn
  116. nn :bp
  117. " Bash(Emacs)风格键盘绑定
  118. imap “光标移动到行首
  119. imap “光标移动到行尾
  120. "imap d0i
  121. "imap d$i " 与自动补全中的绑定冲突
  122. " 恢复上次文件打开位置
  123. set viminfo='10,\"100,:20,%,n~/.viminfo
  124. au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
  125. " 删除buffer时不关闭窗口
  126. command! Bclose call BufcloseCloseIt()
  127. function! BufcloseCloseIt()
  128. let l:currentBufNum = bufnr("%")
  129. let l:alternateBufNum = bufnr("#")
  130. if buflisted(l:alternateBufNum)
  131. buffer #
  132. else
  133. bnext
  134. endif
  135. if bufnr("%") == l:currentBufNum
  136. new
  137. endif
  138. if buflisted(l:currentBufNum)
  139. execute("bdelete! ".l:currentBufNum)
  140. endif
  141. endfunction
  142. " 快捷输入
  143. " 自动完成括号和引号
  144. inoremap 1 ():let leavechar=")"i
  145. inoremap 2 []:let leavechar="]"i
  146. inoremap 3 {}:let leavechar="}"i
  147. inoremap 4 {o}:let leavechar="}"O
  148. inoremap q '':let leavechar="'"i
  149. inoremap w "":let leavechar='"'i
  150. " 缩写
  151. iab idate =strftime("%Y-%m-%d")
  152. iab itime =strftime("%H:%M")
  153. iab imail Stephen
  154. iab iumail stephen1@mail.ustc.edu.cn
  155. iab igmail stephenpcg@gmail.com
  156. iab iname Zhang Cheng
  157. " 插件窗口的宽度,如TagList,NERD_tree等,自己设置
  158. let s:PlugWinSize = 30
  159. " txtbrowser.vim
  160. "
  161. let tlist_txt_settings = 'txt;c:content;f:figures;t:tables'
  162. au BufRead,BufNewFile *.txt setlocal ft=txt
  163. nmap :TlistUpdate
  164. " ShowFunc.vim <-------- 暂时没有使用
  165. "
  166. " F2打开ShowFunc TagList窗口,显示C/C++函数原型
  167. " map ShowFunc
  168. " map! ShowFunc
  169. " taglist.vim
  170. "
  171. " t 打开TagList窗口,窗口在右边
  172. nmap t :TlistToggle
  173. nmap T :TlistToggle
  174. "let Tlist_Ctags_Cmd = '/usr/bin/ctags'
  175. let Tlist_Show_One_File = 0
  176. let Tlist_Exit_OnlyWindow = 1
  177. let Tlist_Use_Right_Window = 1
  178. let Tlist_File_Fold_Auto_Close = 1
  179. let Tlist_GainFocus_On_ToggleOpen = 0
  180. let Tlist_WinWidth = s:PlugWinSize
  181. let Tlist_Auto_Open = 0
  182. let Tlist_Display_Prototype = 0
  183. "let Tlist_Close_On_Select = 1
  184. " minibufexpl.vim
  185. "
  186. " 不需要配置
  187. " OmniCppComplete.vim
  188. "
  189. set completeopt=longest,menu
  190. let OmniCpp_ShowPrototypeInAbbr = 1
  191. let OmniCpp_DefaultNamespaces = ["std"] " 逗号分割的字符串
  192. let OmniCpp_MayCompleteScope = 1
  193. let OmniCpp_ShowPrototypeInAbbr = 0
  194. let OmniCpp_SelectFirstItem = 2
  195. " c-j自动补全,当补全菜单打开时,c-j,k上下选择
  196. " 使用c-h代替c-j,避免与latex-suite冲突
  197. imap pumvisible()?"\":"\"
  198. imap pumvisible()?"\":"\"
  199. imap pumvisible()?"\":"\"
  200. imap pumvisible()?"\":"\"
  201. imap pumvisible()?"\":"\"
  202. " f:文件名补全,l:行补全,d:字典补全,]:tag补全
  203. imap
  204. imap
  205. imap
  206. imap
  207. " NERD_commenter.vim
  208. "
  209. " Toggle单行注释/“性感”注释/注释到行尾/取消注释
  210. map cc ,c
  211. map cs ,cs
  212. map c$ ,c$
  213. map cu ,cu
  214. " NERD tree
  215. "
  216. let NERDTreeShowHidden = 1
  217. let NERDTreeWinPos = "right"
  218. let NERDTreeWinSize = s:PlugWinSize
  219. nmap n :NERDTreeToggle
  220. " DoxygenToolkit.vim
  221. "
  222. " 暂时没有使用
  223. " 更新ctags和cscope索引
  224. " href: 把vim打造成一个真正的ide2.html
  225. " 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令
  226. map :call Do_CsTag()
  227. function! Do_CsTag()
  228. let dir = getcwd()
  229. "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。
  230. if ( DeleteFile(dir, "tags") )
  231. return
  232. endif
  233. if ( DeleteFile(dir, "cscope.files") )
  234. return
  235. endif
  236. if ( DeleteFile(dir, "cscope.out") )
  237. return
  238. endif
  239. if(executable('ctags'))
  240. silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
  241. endif
  242. if(executable('cscope') && has("cscope") )
  243. if(g:isWin)
  244. silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
  245. else
  246. silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files"
  247. endif
  248. silent! execute "!cscope -b"
  249. execute "normal :"
  250. if filereadable("cscope.out")
  251. execute "cs add cscope.out"
  252. endif
  253. endif
  254. " 刷新屏幕
  255. execute "redr!"
  256. endfunction
  257. function! DeleteFile(dir, filename)
  258. if filereadable(a:filename)
  259. if (g:isWin)
  260. let ret = delete(a:dir."\\".a:filename)
  261. else
  262. let ret = delete("./".a:filename)
  263. endif
  264. if (ret != 0)
  265. echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None
  266. return 1
  267. else
  268. return 0
  269. endif
  270. endif
  271. return 0
  272. endfunction
  273. " cscope 绑定
  274. if has("cscope")
  275. set csto=1
  276. set cst
  277. set nocsverb
  278. if filereadable("cscope.out")
  279. cs add cscope.out
  280. endif
  281. set csverb
  282. " s: C语言符号 g: 定义 d: 这个函数调用的函数 c: 调用这个函数的函数
  283. " t: 文本 e: egrep模式 f: 文件 i: include本文件的文件
  284. nmap ss :cs find s =expand("")
  285. nmap sg :cs find g =expand("")
  286. nmap sc :cs find c =expand("")
  287. nmap st :cs find t =expand("")
  288. nmap se :cs find e =expand("")
  289. nmap sf :cs find f =expand("")
  290. nmap si :cs find i ^=expand("")$
  291. nmap sd :cs find d =expand("")
  292. endif
  293. " Quick Fix 设置
  294. map cw :cw
  295. map :cp
  296. map :cn
  297. " lookup file
  298. "
  299. " 增加一行(line 295): let pattern = '\c' . a:pattern
  300. " 按F5或者;ff打开文件搜索窗口
  301. let g:LookupFile_MinPatLength = 0
  302. let g:LookupFile_PreserveLastPattern = 0
  303. let g:LookupFile_PreservePatternHistory = 0
  304. let g:LookupFile_AlwaysAcceptFirst = 1
  305. let g:LookupFile_AllowNewFiles = 0
  306. if filereadable("./filenametags")
  307. let g:LookupFile_TagExpr = '"./filenametags"'
  308. endif
  309. nmap ff :LookupFile
  310. function! LookupFile_IgnoreCaseFunc(pattern)
  311. let _tags = &tags
  312. try
  313. let &tags = eval(g:LookupFile_TagExpr)
  314. let newpattern = '\c' . a:pattern
  315. let tags = taglist(newpattern)
  316. catch
  317. echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
  318. return ""
  319. finally
  320. let &tags = _tags
  321. endtry
  322. " Show the matches for what is typed so far.
  323. let files = map(tags, 'v:val["filename"]')
  324. return files
  325. endfunction
  326. let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
  327. " Buffers Explorer (需要genutils.vim)
  328. "
  329. "
  330. let g:bufExplorerDefaultHelp=0 " Do not show default help.
  331. let g:bufExplorerShowRelativePath=1 " Show relative paths.
  332. let g:bufExplorerSortBy='mru' " Sort by most recently used.
  333. let g:bufExplorerSplitRight=0 " Split left.
  334. let g:bufExplorerSplitVertical=1 " Split vertically.
  335. let g:bufExplorerSplitVertSize = s:PlugWinSize " Split width
  336. let g:bufExplorerUseCurrentWindow=1 " Open in new window.
  337. autocmd BufWinEnter \[Buf\ List\] setl nonumber
  338. "nmap b :BufExplorer
  339. nmap F :BufExplorer
  340. " vim latex suite
  341. "
  342. " 使grep总是生成文件名
  343. set grepprg=grep\ -nH\ $*
  344. " vim默认把空的tex文件设为plaintex而不是tex,导致latex-suite不被加载
  345. let g:tex_flavor='latex'
  346. set iskeyword+=:
  347. autocmd BufEnter *.tex set sw=2
  348. " java complete
  349. "
  350. autocmd Filetype java setlocal omnifunc=javacomplete#Complete
  351. "autocmd Filetype java setlocal completefunc=javacomplete#CompleteParamsInfo
阅读(3746) | 评论(0) | 转发(5) |
给主人留下些什么吧!~~