`
xitonga
  • 浏览: 588443 次
文章分类
社区版块
存档分类
最新评论

vim环境变量配置、背景色配置

 
阅读更多

转自http://blog.csdn.net/mybelief321/article/details/9066249

我们使用vi或者vim的时候,如果想要显示行号,可能会这样做:切换到命令模式,然后输入set nu,再按回车键就显示了;还有就是咱们在编写程序的时候,有的时候会希望按下回车键后,光标不是每次都在行首,而是与上一行的第一个非空格符处对齐,也就是实现所谓的缩排功能,这是你可以在命令模式下输入set autoindent。但是每次这样输入太麻烦了,可不可以在每次利用vim命令编辑时自动就设置好功能呢?

简单说一下我的配置步骤。下表为vim的环境参数(鸟哥那本书上的)

上面都是鸟哥的私房菜里边的,下面简单截图记录一下我的设置,以后想添加功能自己再添加就行了

1、使用命令: cd /etc/vim 进入配置目录

2、使用命令: vim vimrc编辑vimrc文件,我的ubuntu需要使用命令:sudo vim vimrc

3、在vimrc文件的最后一行,添加你想要设置的选项,下图是我想使vim默认的一些功能

4、然后使用 wq保存就可以了,这样设置就成功了。

看了一下很符合口味,就借用了。基本没变动,稍微修改了几句,


注:以下带有网址的都是需要去下载这些插件,点击网址进去就有了

另注:貌似Tlist那个网址被我不小心删掉了

再注:使用archlinux的,可以使用yaourt再AUR中找,很多都是以vim-XXX开头的,命令格式如下:

  1. yaourt-Ssvim-XX

然后再下载,命令如下:

  1. yaourt-Svim-XX


vim的自动补齐一直弄不好,有空找个人帮忙教一下,另外有一些插件功能还没想出来怎么用。现在把弄好的贴上。

另外快捷键一多,没熟悉前总是很难受的,所以弄了一个help.txt文档,放在~/.vim/目录下,每次输入<leader>he就可以打开帮助文档。


新增:抽空弄了一下自动补齐,感觉不错,安装插件neocomplcache

在archlinux中,AUR里面也有,名称为 vim-neocomplcache,所以输入命令:

  1. #yaourt-Svim-neocomplcache
然后在~/.vimrc中补上一行:

  1. letg:neocomplcache_enable_at_startup=1

改变:删掉了关于cscope快捷键,使用官网推荐的快捷方式(其实也没怎么用到)

重新修改了几个快捷键,感觉有些用起来还是不舒服

关于快速编译:永不来autotool系列的工具,找了本书结果有300多页,也没那么多精力去看,然后就偷懒装了一个Qt,用Qt自带的qmake工具生成Makefile工具

用法如下:

  1. #qmake-project

该命令会查找当前目录下的文件生成.pro文件,之后可以修改.pro文件来配置自己想要的功能

  1. #qmake

该命令会根据当前目录下的.pro文件生成对应的Makefile文件

注:在vim中输入:make可以让vim编译器自动根据当前目录下的Makefile文件进行编译



配置文件~/.vimrc

  1. letmapleader="m""比较习惯用;作为命令前缀,右手小拇指直接能按到
  2. "把空格键映射成:
  3. nmap<space>/
  4. "快捷打开编辑vimrc文件的键盘绑定
  5. map<silent><leader>ee:e$HOME/.vimrc<cr>
  6. autocmd!bufwritepost*.vimrcsource$HOME/.vimrc
  7. "^z快速进入shell
  8. nmap<C-Z>:shell<cr>
  9. ""inoremap<leader>n<esc>
  10. "判断操作系统
  11. if(has("win32")||has("win64")||has("win32unix"))
  12. letg:isWin=1
  13. else
  14. letg:isWin=0
  15. endif
  16. "判断是终端还是gvim
  17. ifhas("gui_running")
  18. letg:isGUI=1
  19. else
  20. letg:isGUI=0
  21. endif
  22. "setcursorline"高亮当前行
  23. setnocompatible"关闭兼容模式
  24. syntaxenable"语法高亮
  25. syntaxon
  26. filetypepluginon"文件类型插件
  27. filetypeindenton
  28. "setshortmess=atI"去掉欢迎界面
  29. setautoindent
  30. autocmdBufEnter*:syntaxsyncfromstart
  31. setnu"显示行号
  32. setshowcmd"显示命令
  33. setlz"当运行宏时,在命令执行完成之前,不重绘屏幕
  34. sethid"可以在没有保存的情况下切换buffer
  35. setbackspace=eol,start,indent
  36. setwhichwrap+=<,>,h,l"退格键和方向键可以换行
  37. "setincsearch"增量式搜索
  38. setnohlsearch
  39. sethlsearch"高亮搜索
  40. setignorecase"搜索时忽略大小写
  41. setmagic"额,自己:hmagic吧,一行很难解释
  42. setshowmatch"显示匹配的括号
  43. setnobackup"关闭备份
  44. setnowb
  45. setnoswapfile"不使用swp文件,注意,错误退出后无法恢复
  46. setlbr"在breakat字符处而不是最后一个字符处断行
  47. setai"自动缩进
  48. setsi"智能缩进
  49. setcindent"C/C++风格缩进
  50. setwildmenu
  51. setnofen
  52. setfdl=10
  53. setcmdheight=4"设ckspace和光标键跨越行边界
  54. setwhichwrap+=<,>,h,l
  55. "可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
  56. setmouse=a
  57. setselection=exclusive
  58. setselectmode=mouse,key"置控制窗口大小
  59. "tab转化为4个字符
  60. setexpandtab
  61. setsmarttab
  62. setshiftwidth=4
  63. settabstop=4
  64. "不使用beep或flash
  65. setvbt_vb=
  66. setbackground=dark
  67. sett_Co=256
  68. colorschemetorte
  69. sethistory=400"vim记住的历史操作的数量,默认的是20
  70. setautoread"当文件在外部被修改时,自动重新读取
  71. setmouse=a"在所有模式下都允许使用鼠标,还可以是n,v,i,c等
  72. "在gvim中高亮当前行
  73. if(g:isGUI)
  74. setcursorline
  75. colorschemewombat
  76. hicursorlineguibg=#333333
  77. hiCursorColumnguibg=#333333
  78. "setguifont=Consolas\10
  79. "setguifontwide=Consolas\10
  80. setguifont=DejaVu\Sans\Mono\10
  81. setgfw=DejaVu\Sans\Mono\10
  82. "不显示toolbar
  83. setguioptions-=T
  84. "不显示菜单栏
  85. "setguioptions-=m
  86. endif
  87. "设置字符集编码,默认使用utf8
  88. if(g:isWin)
  89. let&termencoding=&encoding"通常win下的encoding为cp936
  90. setfileencodings=utf8,cp936,ucs-bom,latin1
  91. else
  92. setencoding=utf8
  93. setfileencodings=utf8,gb2312,gb18030,ucs-bom,latin1
  94. endif
  95. "状态栏
  96. setlaststatus=2"总是显示状态栏
  97. highlightStatusLinecterm=boldctermfg=yellowctermbg=blue
  98. "获取当前路径,将$HOME转化为~
  99. function!CurDir()
  100. letcurdir=substitute(getcwd(),$HOME,"~","g")
  101. returncurdir
  102. endfunction
  103. setstatusline=[%n]\%f%m%r%h\\|\\pwd:\%{CurDir()\}\/%f\\\|%=\|\%l,%c\%p%%\\|\ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\\|\\".&fenc)}\\|\%{$USER}\@\%{hostname()}\
  104. "根据给定方向搜索当前光标下的单词,结合下面两个绑定使用
  105. function!VisualSearch(direction)range
  106. letl:saved_reg=@"
  107. execute"normal!vgvy"
  108. letl:pattern=escape(@",'\\/.*$^~[]')
  109. letl:pattern=substitute(l:pattern,"\n$","","")
  110. ifa:direction=='b'
  111. execute"normal?".l:pattern."<cr>"
  112. else
  113. execute"normal/".l:pattern."<cr>"
  114. endif
  115. let@/=l:pattern
  116. let@"=l:saved_reg
  117. endfunction
  118. "用*/#向前/后搜索光标下的单词
  119. vnoremap<silent>*:callVisualSearch('f')<CR>
  120. vnoremap<silent>#:callVisualSearch('b')<CR>
  121. "恢复上次文件打开位置
  122. ""setviminfo='10,\"100,:20,%,n~/.viminfo
  123. ""auBufReadPost*ifline("'\"")>0|ifline("'\"")<=line("$")|exe("norm'\"")|else|exe"norm$"|endif|endif
  124. "删除buffer时不关闭窗口
  125. command!Bclosecall<SID>BufcloseCloseIt()
  126. function!<SID>BufcloseCloseIt()
  127. letl:currentBufNum=bufnr("%")
  128. letl:alternateBufNum=bufnr("#")
  129. ifbuflisted(l:alternateBufNum)
  130. buffer#
  131. else
  132. bnext
  133. endif
  134. ifbufnr("%")==l:currentBufNum
  135. new
  136. endif
  137. ifbuflisted(l:currentBufNum)
  138. execute("bdelete!".l:currentBufNum)
  139. endif
  140. endfunction
  141. "快捷输入
  142. "自动完成括号和引号
  143. inoremap(()<esc>:letleavechar=")"<cr>i
  144. inoremap[[]<esc>:letleavechar="]"<cr>i
  145. inoremap}{}<esc>:letleavechar="}"<cr>i
  146. inoremap{{<esc>o}<esc>:letleavechar="}"<cr>O
  147. inoremap'''<esc>:letleavechar="'"<cr>i
  148. inoremap"""<esc>:letleavechar='"'<cr>i
  149. "插件窗口的宽度,如TagList,NERD_tree等,自己设置
  150. lets:PlugWinSize=25
  151. "taglist.vimdownlo
  152. "设置依次按下wm两个键打开列表
  153. nmapwm:WMToggle<cr>
  154. letTlist_Show_One_File=1
  155. letTlist_Exit_OnlyWindow=1
  156. letg:winManagerWindowLayout='FileExplorer|TagList'
  157. letTlist_Use_Right_Window=0
  158. letTlist_File_Fold_Auto_Close=1
  159. letTlist_GainFocus_On_ToggleOpen=0
  160. letTlist_WinWidth=s:PlugWinSize
  161. letTlist_Auto_Open=0
  162. letTlist_Display_Prototype=0
  163. "letTlist_Close_On_Select=1
  164. "OmniCppComplete.vim
  165. "http://www.vim.org/scripts/script.php?script_id=1520
  166. setcompleteopt=menu
  167. letOmniCpp_ShowPrototypeInAbbr=1
  168. letOmniCpp_DefaultNamespaces=["std"]"逗号分割的字符串
  169. letOmniCpp_MayCompleteScope=1
  170. letOmniCpp_ShowPrototypeInAbbr=0
  171. letOmniCpp_SelectFirstItem=2
  172. "c-j自动补全,当补全菜单打开时,c-j,k上下选择
  173. "imap<expr><c-u>pumvisible()?"\<C-N>":"\<C-X><C-O>"
  174. "imap<expr><c-i>pumvisible()?"\<C-P>":"\<esc>"
  175. "f:文件名补全,l:行补全,d:字典补全,]:tag补全
  176. "imap<C-]><C-X><C-]>
  177. imap<C-F><C-X><C-F>
  178. imap<C-D><C-X><C-D>
  179. imap<C-L><C-X><C-L>
  180. "NERD_commenter.vim
  181. "http://www.vim.org/scripts/script.php?script_id=1218
  182. "Toggle单行注释/“性感”注释/注释到行尾/取消注释
  183. map<leader>cc,c<space>
  184. map<leader>cs,cs
  185. map<leader>c$,c$
  186. map<leader>cu,cu
  187. "-----------------------------------------------------------------
  188. ""plugin-DoxygenToolkit.vim由注释生成文档,并且能够快速生成函数标准注释
  189. "-----------------------------------------------------------------
  190. letg:DoxygenToolkit_authorName="Asins-asinsimpleATgmailDOTcom"
  191. letg:DoxygenToolkit_briefTag_funcName="yes"
  192. map<leader>da:DoxAuthor<CR>
  193. map<leader>df:Dox<CR>
  194. map<leader>db:DoxBlock<CR>
  195. map<leader>dc<End>a/**/<LEFT><LEFT><LEFT>
  196. "NERDtree
  197. "http://www.vim.org/scripts/script.php?script_id=1658
  198. letNERDTreeShowHidden=1
  199. letNERDTreeWinPos="left"
  200. letNERDTreeWinSize=s:PlugWinSize
  201. nmapwn:NERDTreeToggle<cr>
  202. "DoxygenToolkit.vim
  203. "http://www.vim.org/scripts/script.php?script_id=987
  204. "暂时没有使用
  205. "更新ctags和cscope索引
  206. "href:http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html
  207. "稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令
  208. map<F6>:callDo_CsTag()<cr>
  209. function!Do_CsTag()
  210. letdir=getcwd()
  211. "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。
  212. if(DeleteFile(dir,"tags"))
  213. return
  214. endif
  215. if(DeleteFile(dir,"cscope.files"))
  216. return
  217. endif
  218. if(DeleteFile(dir,"cscope.out"))
  219. return
  220. endif
  221. if(executable('ctags'))
  222. silent!execute"!ctags-R--c++-kinds=+p--fields=+iaS--extra=+q."
  223. endif
  224. if(executable('cscope')&&has("cscope"))
  225. if(g:isWin)
  226. silent!execute"!dir/s/b*.c,*.cpp,*.h,*.java,*.cs>>cscope.files"
  227. else
  228. silent!execute"!find.-iname'*.[ch]'-o-name'*.cpp'>cscope.files"
  229. endif
  230. silent!execute"!cscope-b"
  231. execute"normal:"
  232. iffilereadable("cscope.out")
  233. execute"csaddcscope.out"
  234. endif
  235. endif
  236. "刷新屏幕
  237. execute"redr!"
  238. endfunction
  239. function!DeleteFile(dir,filename)
  240. iffilereadable(a:filename)
  241. if(g:isWin)
  242. letret=delete(a:dir."\\".a:filename)
  243. else
  244. letret=delete("./".a:filename)
  245. endif
  246. if(ret!=0)
  247. echohlWarningMsg|echo"Failedtodelete".a:filename|echohlNone
  248. return1
  249. else
  250. return0
  251. endif
  252. endif
  253. return0
  254. endfunction
  255. "cscope绑定
  256. ifhas("cscope")
  257. setcsto=1
  258. setcst
  259. setnocsverb
  260. setcscopequickfix=s-,c-,d-,i-,t-,e-
  261. iffilereadable("cscope.out")
  262. csaddcscope.out
  263. endif
  264. endif
  265. "quickfix配置"
  266. map<F3>:cw<cr>
  267. map<F2>:cn<cr>
  268. "Vimwiki配置
  269. letg:vimwiki_list=[{'path':'~/Dropbox/MyWiki/my_site/',
  270. \'path-html':'~/Dropbox/MyWiki/my_site_html/',
  271. \'html-header':'~/Dropbox/MyWiki/templates/header.tpl',
  272. \'html-footer':'~/Dropbox/MyWiki/templates/footer.tpl'}]
  273. letg:vimwiki_camel_case=0
  274. letwiki={}
  275. letwiki.path='~/Dropbox/MyWiki/my_site/'
  276. letwiki.nested_syntaxes={'python':'python','c++':'cpp'}
  277. letg:vimwiki_list=[wiki]
  278. "pythoncomplete配置
  279. autocmdfiletypepythonsetomnifunc=pythoncomplete#Complete
  280. "定义在插入模式下
  281. "使用ctrl+j为向下一行
  282. inoremap<C-h><Left>
  283. inoremap<C-j><Down>
  284. inoremap<C-k><Up>
  285. inoremap<C-l><Right>
  286. "可以快速保存和退出
  287. nmap<leader>q:q<CR>
  288. nmap<leader>w:w<CR>
  289. nmap<leader>qq:q!<CR>
  290. nmap<leader>wq:wq<CR>
  291. "quicklygotohelpmenuofthisfunction
  292. nmap<leader>an:Man3<cword><CR>
  293. "superenter,itcanguciklygotothenextline
  294. imape<CR><End><CR>
  295. imap<leader>dd<Esc>ddi
  296. imape;<End>;
  297. map<silent><leader>he:tabnew~/.vim/help.txt<CR>
  298. "
  299. "设置F5编译,F6运行
  300. func!CompileGcc()
  301. exec"w"
  302. letcompilecmd="!gcc"
  303. letcompileflag="-o%<"
  304. ifsearch("mpi.h")!=0
  305. letcompilecmd="!mpicc"
  306. endif
  307. ifsearch("glut.h")!=0
  308. letcompileflag.="-lglut-lGLU-lGL"
  309. endif
  310. ifsearch("cv.h")!=0
  311. letcompileflag.="-lcv-lhighgui-lcvaux"
  312. endif
  313. ifsearch("omp.h")!=0
  314. letcompileflag.="-fopenmp"
  315. endif
  316. ifsearch("math.h")!=0
  317. letcompileflag.="-lm"
  318. endif
  319. execcompilecmd."%".compileflag
  320. endfunc
  321. func!CompileGpp()
  322. exec"w"
  323. letcompilecmd="!g++"
  324. letcompileflag="-o%<"
  325. ifsearch("mpi.h")!=0
  326. letcompilecmd="!mpic++"
  327. endif
  328. ifsearch("glut.h")!=0
  329. letcompileflag.="-lglut-lGLU-lGL"
  330. endif
  331. ifsearch("cv.h")!=0
  332. letcompileflag.="-lcv-lhighgui-lcvaux"
  333. endif
  334. ifsearch("omp.h")!=0
  335. letcompileflag.="-fopenmp"
  336. endif
  337. ifsearch("math.h")!=0
  338. letcompileflag.="-lm"
  339. endif
  340. execcompilecmd."%".compileflag
  341. endfunc
  342. func!RunPython()
  343. exec"!python%"
  344. endfunc
  345. func!CompileJava()
  346. exec"!javac%"
  347. endfunc
  348. func!CompileCode()
  349. exec"w"
  350. if&filetype=="cpp"
  351. exec"callCompileGpp()"
  352. elseif&filetype=="c"
  353. exec"callCompileGcc()"
  354. elseif&filetype=="python"
  355. exec"callRunPython()"
  356. elseif&filetype=="java"
  357. exec"callCompileJava()"
  358. endif
  359. endfunc
  360. func!RunResult()
  361. exec"w"
  362. ifsearch("mpi.h")!=0
  363. exec"!mpirun-np4./%<"
  364. elseif&filetype=="cpp"
  365. exec"!./%<"
  366. elseif&filetype=="c"
  367. exec"!./%<"
  368. elseif&filetype=="python"
  369. exec"callRunPython"
  370. elseif&filetype=="java"
  371. exec"!java%<"
  372. endif
  373. endfunc
  374. map<F5>:callCompileCode()<CR>
  375. imap<F5><ESC>:callCompileCode()<CR>
  376. map<F6>:callRunResult()<CR>
  377. "自动补齐功能,需要先安装neocomplcache
  378. letg:neocomplcache_enable_at_startup=1
  379. imap<F4><ESC>:A<CR>i
  380. nmap<F4>:A<CR>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics