最近在学习使用python2.7编写自动化运维脚本,需要使用vim。

因为是新手,完全不懂如何进行插件配置,只是写脚本,只需要配置一下.vimrc文件,有语法高亮我就可以了。下面是相关配置

#基本配置
set nocompatible "关闭与vi的兼容模式
set number "显示行号
set nowrap    "不自动折行
set showmatch    "显示匹配的括号
set scrolloff=3        "距离顶部和底部3行"
set encoding=utf-8  "编码
set fenc=utf-8      "编码
set mouse=a        "启用鼠标
set hlsearch        "搜索高亮
syntax on    "语法高亮
#为py文件添加下支持pep8风格的配置
au BufNewFile,BufRead *.py
\ set tabstop=4   "tab宽度
\ set softtabstop=4  
\ set shiftwidth=4   
\ set textwidth=79  "行最大宽度
\ set expandtab       "tab替换为空格键
\ set autoindent      "自动缩进
\ set fileformat=unix   "保存文件格式
#代码折叠
set foldmethod=indent
set foldlevel=99
#一建执行python脚本
map <F5> :call RunPython()<CR>
func! RunPython()
    exec "W"
    if &filetype == 'python'
        exec "!time python2.7 %"
    endif
endfunc
#使用F6按键绑定pydoc 帮助文件
nnoremap <buffer> F6 :<C-u>execute "!pydoc2 " . expand("<cword>")<CR>