免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1366 | 回复: 0
打印 上一主题 下一主题

Ubuntu Gutsy-配置VIM下面的Python环境-2 [复制链接]

论坛徽章:
1
15-16赛季CBA联赛之北控
日期:2022-03-04 22:35:50
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-05 22:42 |只看该作者 |倒序浏览

原文:
http://hi.baidu.com/camark/blog/item/97da11235f8e624a93580709.html

对于上一篇Blog的内容进行了增强,新增功能如下:
1、对于Python关键字的增强:
譬如输入$p,自动替换为print
2、对于代码片段的支持(需要一个改动的imaps.vim文件,保持到~/.vim/plugin即可):
cfun按Tab得到def语句
cclass得到class语句
cclassinit得到class的init语句
cclassmethod得到class的method
cfor得到for语句
还有cif、cifelse等你功能
3、Python直接运行功能,按F7直接运行
具体内容如下:
" 自动补全命令时候使用菜单式匹配列表
set wildmenu
" 允许退格键删除
set backspace=2
" 启用鼠标
set mouse=a
" 文件类型
filetype on
filetype plugin on
filetype indent on
" 设置编码自动识别, 中文引号显示
"set fileencodings=utf-8,cp936,big5,euc-jp,euc-kr,latin1,ucs-bom
set fileencodings=utf-8,gbk
set ambiwidth=double
" 移动长行
nnoremap  gj
nnoremap  gk
" 高亮
syntax on
" 设置高亮搜索
set hlsearch
" 输入字符串就显示匹配点
set incsearch
" 输入的命令显示出来,看的清楚些。
set showcmd
" 打开当前目录文件列表
map  :e .
" Taglist
let Tlist_File_Fold_Auto_Close=1
set updatetime=1000
map  :Tlist
" 按 F8 智能补全
inoremap  
" vim 自动补全 Python 代码
" 来自http://vim.sourceforge.net/scripts/script.php?script_id=850
autocmd FileType python set complete+=k~/.vim/tools/pydiction
" 自动使用新文件模板
autocmd BufNewFile *.py 0r ~/.vim/template/simple.py
"自动关键字补全,譬如输入$p,自动变换为print;输入$c,自动添加注释行
au FileType python inoremap  $r return
au FileType python inoremap  $s self
au FileType python inoremap  $i import
au FileType python inoremap  $p print
au FileType python inoremap  $c ####kla
au FileType python inoremap  $d """"""0
"设置Python运行
autocmd FileType python set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd FileType python set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
"设置Python 代码片段,使用Ctrl+J在模板参数之间跳转
autocmd FileType python inorea  cfun =IMAP_PutTextWithMovement("def ():\n\nreturn ")
autocmd FileType python inorea  cclass =IMAP_PutTextWithMovement("class :\n")
autocmd FileType python inorea  cfor =IMAP_PutTextWithMovement("for  in :\n")
autocmd FileType python inorea  cif =IMAP_PutTextWithMovement("if :\n")
autocmd FileType python inorea  cifelse =IMAP_PutTextWithMovement("if :\n\nelse:\n")
autocmd FileType python inorea  cclassinit =IMAP_PutTextWithMovement("def __init__(self,):\n")
autocmd FileType python inorea  cclassmethod =IMAP_PutTextWithMovement("def (self,):\n")
function! Python_Eval_VSplit() range
    "let src=tempname()
    let dst=tempname()
    "execute ": " . a:firstline . ",". a:lastline . ' w '.srca
    let filename=bufname("%")
    execute ":!python " . filename . " > " . dst
    execute ":pedit! " . dst
endfunction
"按F7自动运行buffer里面的内容
au FileType python map  :call Python_Eval_VSplit()
imap  
"Format the statusline
"Nice statusbar
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flag
set statusline+=[
if v:version >= 600
set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
endif
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
set statusline+=\ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
"set statusline+=%2*0x%-8B\ " current char
set statusline+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/31/showart_675902.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP