Linux VIM8.1 Python3 编辑器配置文件

实现功能:

  • 自动补全(包括函数模块方法补全)
  • 自动代码标准格式化
  • 自动检查代码错误
  • 自定义头文件
  • 自动括号补全
  • 缩进指示线
  • 代码一键折叠
  • 代码一键执行
  • 图形化断点调试
  • 分屏终端导入调试
  • 分屏目录窗口
  • 美化主题窗口栏位
  • 指向查找目录文件
  • 终端浏览器

.vimrc 配置文件:

""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"                   - kevin -                         
"
"---------------------简单配置------------------------
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              "语法高亮
set backspace=indent,eol,start "启动删除设置"

"-------------------------Debugger调试器F1----------------------------

let g:sendtorepl_invoke_key = "f"           "传送代码快捷键,默认为<leader>w
let g:repl_position = 0                     "0表示出现在下方,1表示出现在上方,2在左边,3在右边
let g:repl_stayatrepl_when_open = 0         "打开REPL时是回到原文件(1)还是停留在REPL窗口中(0
let g:repl_checkpoint_position = '~/.temp/'
let g:repl_auto_sends = ['class ', 'def ']
let g:repl_cursor_down = 1

let g:repl_program = {
    \    "python": "python3",
    \    "default": "bash"
    \    }        

let g:repl_exit_commands = {
            \    "python": "quit()",
            \    "bash": "exit",
            \    "zsh": "exit",
            \    "default": "exit",
            \    }

"------------为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 splitbelow
set splitright

"分割窗口参数
":vs  或者 :vsplit  将当前窗口竖直分割,并在上面新窗口中显示当前文件
":vs filename 将当前窗口竖直分割,新文件在新窗口中显示
":sp 或者:sv或者:split  将当前窗口水平分割,并在左边新窗口中显示当前文件
":sp filename 将当前窗口竖直分割,新文件在左边新窗口中显示
":new 新建文件并竖直分割
":vnew 新建文件并水平分割

"--------------添加头文件信息-------------------
function HeaderPython()
    call setline(1, "#!/usr/bin/env python")
    call append(1, "# -*- coding: utf-8 -*-")
    call append(2, "# @Time: " . strftime('%Y-%m-%d %T', localtime()))
    call append(3, "# @Author: xiangsikai")
    call append(4, "# #############  调试器  ############## #")
    call append(5, "# from pudb import set_trace;set_trace()#")

    normal G
    normal o
    normal o
endf
autocmd bufnewfile *.py call HeaderPython()

"--------------代码折叠配置-----------------------
set foldmethod=indent
set foldlevel=99

"使用zc按键来创建折叠,使用za来打开或者关闭折叠。
"za经常会误输入,空格快捷键来替代za:
nnoremap <space> za

"--------------一键执行python代码配置--------------
"按 F4 执行代码
map <F4> :call RunPython()<CR>
func! RunPython()
    exec "W"
    if &filetype == 'python'
        exec "!time python3 %"
    endif
endfunc

"-----------------Vundle 插件----------------------
set nocompatible              " be iMproved, required
filetype off                  " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"--------------------------------------------------
"      使用:PluginInstall下载下面的插件
"--------------------------------------------------
"
"  其他:常用命令 ↓
"
"  :PluginList         - 列表配置插件
"  :PluginInstall      - 装的插件;添加”!“
"  :PluginUpdate       - 更新
"  :PluginSearch foo   - 搜索foo;添加”!来刷新本地缓存
"  :PluginClean        - 确认移除未使用的插件;添加”!”
"
"-----let Vundle manage Vundle, required-----------
Plugin 'VundleVim/Vundle.vim'

"Debugger调试器F1
Plugin 'sillybun/vim-repl'
autocmd FileType python map <buffer> <F1> :REPLToggle<CR>

"YCM自动补全
Plugin 'Valloric/YouCompleteMe'

"vim8自动补全插件
Plugin 'maralla/completor.vim'
let g:completor_python_binary = '/usr/bin/python3'

"vim8自动缩进插件
Plugin 'vim-scripts/indentpython.vim' 

"vim8语法检查插件
Plugin 'vim-syntastic/syntastic'
"vim8添加flake8代码风格检查
Plugin 'nvie/vim-flake8'
" F2启用代码检查
autocmd FileType python map <buffer> <F2> :call Flake8()<CR>
"保存文件时显示错误
"autocmd BufWritePost *.py call flake8#Flake8()

"配色方案1 vundle下载
Plugin 'altercation/vim-colors-solarized'
"light or dark 两种配色主题
syntax enable
set background=light

"树形目录
Plugin 'scrooloose/nerdtree'
"树形目录快捷键 ctrl + n
map <C-n> :NERDTreeToggle<CR>
"设置忽略文件
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
"为nerdtree添加git支持
Plugin 'Xuyuanp/nerdtree-git-plugin'
"如果你想用tab键
Plugin 'jistr/vim-nerdtree-tabs'

"美化栏
Plugin 'Lokaltog/vim-powerline'

"缩进指示线  | 开关:IndentLinesToggle
Plugin 'Yggdroot/indentLine'

"自动格式化工具 | 运行:Autopep8 |效果自动一招pep8标准自动格式化代码
Plugin 'tell-k/vim-autopep8'
"设置快捷键F3代替:Autopep8
autocmd FileType python noremap <buffer> <F3> :call Autopep8()<CR>

"自动补全括号引号等
Plugin 'jiangmiao/auto-pairs'

"搜索插件 | ctrl+p 然后输入你要寻找的文件就行了
Plugin 'kien/ctrlp.vim'

"搜索引擎使用了 the_silver_searcher 
"使用:Ag [options] {pattern} [{directory}]
Plugin 'rking/ag.vim'

"git集成插件 | vim内运行git命令
Plugin 'tpope/vim-fugitive'

"其他模块
Plugin 'tomasr/molokai'
Plugin 'vim-scripts/phd'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'octol/vim-cpp-enhanced-highlight'
Plugin 'derekwyatt/vim-fswitch'
Plugin 'vim-scripts/a.vim'
Plugin 'kshenoy/vim-signature'
Plugin 'vim-scripts/BOOKMARKS--Mark-and-Highlight-Full-Lines'
Plugin 'majutsushi/tagbar'
Plugin 'vim-scripts/indexer.tar.gz'
Plugin 'vim-scripts/DfrankUtil'
Plugin 'vim-scripts/vimprj'
Plugin 'dyng/ctrlsf.vim'
Plugin 'vim-scripts/DrawIt'
Plugin 'SirVer/ultisnips'
Plugin 'rdnetto/YCM-Generator'
Plugin 'derekwyatt/vim-protodef'
"Plugin 'gcmt/wildfire.vim'  "视图模式多选
Plugin 'sjl/gundo.vim'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'suan/vim-instant-markdown'
Plugin 'qpkorr/vim-bufkill'
Plugin 'skywind3000/asyncrun.vim'

"--------------------------------------------
call vundle#end()            " required
filetype plugin indent on    " required
"--------------------------------------------