Chinaunix首页 | 论坛 | 博客
  • 博客访问: 281163
  • 博文数量: 38
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 221
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-25 17:36
文章分类

全部博文(38)

文章存档

2015年(1)

2014年(37)

分类: Python/Ruby

2014-12-05 16:42:21

下载各种插件

首先去下载Python相关插件plugin:

1, 提供代码折叠功能

2, 提供查看文件折叠/展开列表功能

3, 提供快速代码注释功能

4, 提供源代码结构及函数,变量列表

5, 提供Tab补全代码功能

 

配置vimrc文件

:scriptnames 调出所有vim脚本
:e $VIM/_vimrc 打开vim配置文件。然后就像一般文本操作写下自定义的Vim配置

1,对python_fold的设置,(用法:zn, zc, zo 

有 6 种方法来选定折叠:
manual           手工定义折叠
indent             更多的缩进表示更高级别的折叠
expr                用表达式来定义折叠
syntax             用语法高亮来定义折叠
diff                  对没有更改的文本进行折叠
marker            对文中的标志折叠

  1. set foldmethod=indent ''设置折叠方式  

2,对NERD_tree的设置,假设绑定到F2

  1. nmap  :NERDTreeToggle  

3,不需要配置,直接扔进Plugin文件夹内即可。(用法:\x ,支持单行,块

4,对tagList的设置,绑定到F3(需要安装ctags,并设置环境变量PATH)

  1. "进行Tlist的设置  
  2. filetype on  
  3. let Tlist_Show_Menu = 1  
  4. "TlistUpdate可以更新tags  
  5. map  :silent! Tlist  "按下F3就可以呼出Taglist  
  6. let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行  
  7. let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边  
  8. let Tlist_Show_One_File=1 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1  
  9. let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏  
  10. let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动退出vim  
  11. let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理  
  12. let Tlist_Inc_Winwidth=  

5,配置Pydiction自动tab代码补全

把python_pydiction.vim文件拷贝到../ftplugin中
把complete-dict拷贝到../tools/pydiction中


  1. filetype plugin on   
  2. let g:pydiction_location = 'C:\Program Files\Vim\vim73\tools\pydiction\complete-dict'  
  3. let g:pydiction_menu_height = 20  


6,配置Python解释器,绑定到F5运行,F6编译

  1. autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"  
  2. autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m  
  3. autocmd BufRead *.py nmap  :!python %  
  4. autocmd BufRead *.py nmap  :make  
  5. autocmd BufRead *.py copen "如果是py文件,则同时打开编译信息窗口  

 

最后放出vimrc当前的配置

  1. set nocompatible  
  2. set number  
  3. syntax enable  
  4. syntax on "打开高亮  
  5. colorscheme desert  
  6. set nocompatible "不要vim模仿vi模式  
  7. set foldmethod=indent "设置折叠  
  8. source $VIMRUNTIME/vimrc_example.vim  
  9. source $VIMRUNTIME/mswin.vim  
  10. behave mswin  
  11.   
  12.   
  13. set diffexpr=MyDiff()  
  14. function MyDiff()  
  15.   let opt = '-a --binary '  
  16.   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif  
  17.   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif  
  18.   let arg1 = v:fname_in  
  19.   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif  
  20.   let arg2 = v:fname_new  
  21.   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif  
  22.   let arg3 = v:fname_out  
  23.   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif  
  24.   let eq = ''  
  25.   if $VIMRUNTIME =~ ' '  
  26.     if &sh =~ '\
  27.       let cmd = '""' . $VIMRUNTIME . '\diff"'  
  28.       let eq = '"'  
  29.     else  
  30.       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'  
  31.     endif  
  32.   else  
  33.     let cmd = $VIMRUNTIME . '\diff'  
  34.   endif  
  35.   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq  
  36. endfunction  
  37.   
  38. "  
  39. if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型  
  40.     let g:iswindows=1  
  41. else  
  42.     let g:iswindows=0  
  43. endif  
  44. autocmd BufEnter * lcd %:p:h  
  45.   
  46. if has("autocmd")  
  47.     filetype plugin indent on "根据文件进行缩进  
  48.     augroup vimrcEx  
  49.         au!  
  50.         autocmd FileType text setlocal textwidth=78  
  51.         autocmd BufReadPost *  
  52.                     \ if line("'\"") > 1 && line("'\"") <= line("$") |  
  53.                     \ exe "normal! g`\"" |  
  54.                     \ endif  
  55.     augroup END  
  56. else  
  57.     set autoindent " always set autoindenting on   
  58. endif " has("autocmd")  
  59. set tabstop=4 "让一个tab等于4个空格  
  60. set vb t_vb=  
  61. set nowrap "不自动换行  
  62. set hlsearch "高亮显示结果  
  63. set incsearch "在输入要搜索的文字时,vim会实时匹配  
  64. set backspace=indent,eol,start whichwrap+=<,>,[,] "允许退格键的def使用  
  65. if(g:iswindows==1) "允许鼠标的使用  
  66.     "防止linux终端下无法拷贝  
  67.     if has('mouse')  
  68.         set mouse=a  
  69.     endif  
  70.     au GUIEnter * simalt ~x  
  71. endif  
  72.   
  73. "定制GUI界面  
  74. set go= "无菜单、工具栏"  
  75.   
  76. "配置Python的编译&运行(F5运行脚本,F6编译脚本  
  77. autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"  
  78. autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m  
  79. autocmd BufRead *.py nmap  :!python %  
  80. autocmd BufRead *.py nmap  :make  
  81. autocmd BufRead *.py copen "如果是py文件,则同时打开编译信息窗口  
  82.   
  83. "NERDTree,提供查看文件折叠/展开列表功能  
  84. nmap  :NERDTreeToggle  
  85. "imap   :NERDTreeToggle  
  86.   
  87. "进行Tlist的设置  
  88. filetype on  
  89. let Tlist_Show_Menu = 1  
  90. "TlistUpdate可以更新tags  
  91. map  :silent! Tlist  "按下F3就可以呼出Taglist  
  92. let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行  
  93. let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边  
  94. let Tlist_Show_One_File=1 "让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1  
  95. let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏  
  96. let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动退出vim  
  97. let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理  
  98. let Tlist_Inc_Winwidth=0  
  99. "set tags=C:\Program Files\Vim\vim73\Tags "设置tags文件路径  
  100.   
  101.   
  102. map  :call Do_CsTag()  
  103. nmap s :cs find s =expand(""):copen  
  104. nmap g :cs find g =expand("")  
  105. nmap c :cs find c =expand(""):copen  
  106. nmap t :cs find t =expand(""):copen  
  107. nmap e :cs find e =expand(""):copen  
  108. nmap f :cs find f =expand(""):copen  
  109. nmap i :cs find i ^=expand("")$:copen  
  110. nmap d :cs find d =expand(""):copen  
  111. function Do_CsTag()  
  112.     let dir = getcwd()  
  113.     if filereadable("tags")  
  114.         if(g:iswindows==1)  
  115.             let tagsdeleted=delete(dir."\\"."tags")  
  116.         else  
  117.             let tagsdeleted=delete("./"."tags")  
  118.         endif  
  119.         if(tagsdeleted!=0)  
  120.             echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None  
  121.             return  
  122.         endif  
  123.     endif  
  124.     if has("cscope")  
  125.         silent! execute "cs kill -1"  
  126.     endif  
  127.     if filereadable("cscope.files")  
  128.         if(g:iswindows==1)  
  129.             let csfilesdeleted=delete(dir."\\"."cscope.files")  
  130.         else  
  131.             let csfilesdeleted=delete("./"."cscope.files")  
  132.         endif  
  133.         if(csfilesdeleted!=0)  
  134.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None  
  135.             return  
  136.         endif  
  137.     endif  
  138.     if filereadable("cscope.out")  
  139.         if(g:iswindows==1)  
  140.             let csoutdeleted=delete(dir."\\"."cscope.out")  
  141.         else  
  142.             let csoutdeleted=delete("./"."cscope.out")  
  143.         endif  
  144.         if(csoutdeleted!=0)  
  145.             echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None  
  146.             return  
  147.         endif  
  148.     endif  
  149.     if(executable('ctags'))  
  150.         "silent! execute "!ctags -R --c-types=+p --fields=+S *"  
  151.         silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."  
  152.     endif  
  153.     if(executable('cscope') && has("cscope") )  
  154.         if(g:iswindows!=1)  
  155.             silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"  
  156.         else  
  157.             silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"  
  158.         endif  
  159.         silent! execute "!cscope -b"  
  160.         execute "normal :"  
  161.         if filereadable("cscope.out")  
  162.             execute "cs add cscope.out"  
  163.         endif  
  164.     endif  
  165. endfunction  
  166.   
  167. "对NERD_commenter的设置  
  168. "let NERDShutUp=1  
  169.   
  170. " 使用F8打开  
  171. "nnoremap   :TlistToggle  
  172.   
  173. "设置文件浏览器窗口显示方式  
  174. "通过WinManager插件来将TagList窗口和netrw窗口整合起来  
  175. let g:winManagerWindowLayout='FileExplorer|TagList'  
  176. nmap wm :WMToggle  
  177.   
  178. "设置PythonDict用Tab自动补全功能  
  179. filetype plugin on   
  180. let g:pydiction_location = 'C:\Program Files\Vim\vim73\tools\pydiction\complete-dict'  
  181. let g:pydiction_menu_height = 20  



基本上以上的配置可以跑python的脚本了。


 OK,Let's enjoy it~

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