vim配置python开发环境

vim配置python开发环境



一、安装vim

sudo apt-get install vim



二、vim基础配置



#Centos6.5

/usr/share/vim/vim72







vi /etc/vim/vimrc(添加如下内容):





set nocompatible

"source $VIMRUNTIME/vimrc_example.vim "软件安装默认,source入vimrc_example.vim后,在设置encoding=utf-8时,将导致中文菜单乱码难以解决

source $VIMRUNTIME/mswin.vim

behave mswin



" 字体、字号

set guifont=Courier\ New:h13



" 编码设置

set encoding=utf-8

set langmenu=zh_CN.UTF-8

language message zh_CN.UTF-8

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

set ffs=unix,dos,mac

set ff=unix                            "设置文件格式为UNIX格式



set diffexpr=MyDiff()

function MyDiff()

  let opt = '-a --binary '

  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif

  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif

  let arg1 = v:fname_in

  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif

  let arg2 = v:fname_new

  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif

  let arg3 = v:fname_out

  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif

  let eq = ''

  if $VIMRUNTIME =~ ' '

    if &sh =~ '\<cmd'

      let cmd = '""' . $VIMRUNTIME . '\diff"'

      let eq = '"'

    else

      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'

    endif

  else

    let cmd = $VIMRUNTIME . '\diff'

  endif

  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq

endfunction

"================================





colorscheme darkblue2        " 配色方案darkblue2 

syntax on                    " 打开语法高亮

syntax on                    " 开启文件类型侦测

filetype indent on           " 针对不同的文件类型采用不同的缩进格式

filetype plugin on           " 针对不同的文件类型加载对应的插件

filetype plugin indent on

set tabstop=4                " 设置tab键的宽度

set shiftwidth=4             " 换行时行间交错使用4个空格

set autoindent               " 自动对齐

set backspace=2              " 设置退格键可用

set cindent shiftwidth=4     " 自动缩进4空格

set smartindent              " 智能自动缩进

set ai!                      " 设置自动缩进

set number                   " 显示行号

set showmatch                " 显示括号配对情况

set mouse=a                  " 启用鼠标

set ruler                    " 右下角显示光标位置的状态行

set incsearch                " 查找book时,当输入/b时会自动找到

set hlsearch                 " 开启高亮显示结果

set incsearch                " 开启实时搜索功能

set nowrapscan               " 搜索到文件两端时不重新搜索

set nocompatible             " 关闭兼容模式

set vb t_vb=                 " 关闭提示音

set cursorline              " 突出显示当前行

set hidden                   " 允许在有未保存的修改时切换缓冲区

set list                     

set listchars=tab:\|\ ,        " 显示Tab符,使用一高亮竖线代替

"set listchars=tab:>-,trail:-    " 显示Tab符,使用" >-- "代替



if has("gui_running")

    au GUIEnter * simalt ~x  " 窗口启动时自动最大化

    "set guioptions-=m       " 隐藏菜单栏

    "set guioptions-=T       "隐藏工具栏,注释时启用工具栏,里面有个保存当前会话和加载会话挺有用,当然也可以用命令实现。

    set guioptions-=L       " 隐藏左侧滚动条

    set guioptions-=r       " 隐藏右侧滚动条

    "set guioptions-=b       " 隐藏底部滚动条

    "set showtabline=0       " 隐藏Tab栏

endif



set writebackup              " 设置无备份文件

set nobackup

set autochdir                " 设定文件浏览器目录为当前目录

"set nowrap                  " 设置不自动换行

set foldmethod=syntax        " 选择代码折叠类型

set foldlevel=100            " 禁止自动折叠



"多文档编辑 minibufexpl.vim

let g:miniBufExplMapCTabSwitchBufs=1 

let g:miniBufExplMapWindowsNavVim=1 

let g:miniBufExplMapWindowNavArrows=1



" WinManager :WMToggle

let g:winManagerWindowLayout='FileExplorer|TagList'  

nmap wm :WMToggle<cr>



" cscope  

set cscopequickfix=s-,c-,d-,i-,t-,e-



" SuperTab :SuperTabHelp  

let g:SuperTabRetainCompletionType=2  

let g:SuperTabDefaultCompletionType="<C-X><C-O>"



" 热键映射  

nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>   " cscope插件热键  

nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>  

nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>  

nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>  

nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>  

nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>  

nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>{1}lt;CR>  

nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>  

 

nmap <F6> :cn<cr>    " cw模式下热键  

nmap <F7> :cp<cr>  

 

map <F11> :A<cr>     " 头文件与源文件切换  

  

map <F5> :w<CR>:make<CR>   ”执行编译MAKE  

map <F5><F5> :make clean<CR>    

 

vmap <C-c> "yy   “复制模拟 CTRL + C  

vmap <C-x> "yd  

nmap <C-v> "yp  

vmap <C-v> "yp  

nmap <C-a> ggvG$  

  

nmap <C-s> :wa<cr>  “模拟WIN 保存 CTRL + S  

imap <C-s> <Esc>:wa<cr>i<Right>



" For Haskell

:let hs_highlight_delimiters=1            " 高亮定界符

:let hs_highlight_boolean=1               " 把True和False识别为关键字

:let hs_highlight_types=1                 " 把基本类型的名字识别为关键字

:let hs_highlight_more_types=1            " 把更多常用类型识别为关键字

:let hs_highlight_debug=1                 " 高亮调试函数的名字

:let hs_allow_hash_operator=1             " 阻止把#高亮为错误





set laststatus=2                          " 开启状态栏信息

set cmdheight=1                           " 命令行的高度,默认为1,这里可以重设



" 状态行显示的内容 [包括系统平台、文件类型、坐标、所占比例、时间等]

set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %y%r%m%*%=\ %{strftime(\"%y/%m/%d\ -\ %H:%M\")}































"==============================







"支持中文 

set encodings=utf-8,gbk

set langmenu=zh_CN.UTF-8

language message zh_CN.UTF-8



set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

set ffs=unix,dos,mac

set ff=unix  "设置文件格式为UNIX格式



set fileencodings=utf-8,gbk

set ambiwidth=double   

  

" 允许退格键删除和 tab 操作  

set smartindent       

set smarttab       

set expandtab       

set tabstop=4       

set softtabstop=4       

set shiftwidth=4       

set backspace=2   

set textwidth=79   

       

" 启用鼠标       

set mouse=a       

         

" 启用行号       

set  nu



三、设置代码补全功能



VIM python 自动补全插件:



1.简单python关键词补全

2.python 函数补全带括号

3.python 模块补全

4.python 模块内函数,变量补全

5.from module import sub-module 补全 



注意:pydiction 1.0 之后版本安装配置,适用VIM7之后的版本。 



1、安装



wget http://www.pythonclub.org/_media/python-basic/pydiction-1.2.zip

unzip pydiction-1.2.zip





" ~/.vim/after/ftplugin 和~/.vim/tools/pydiction/目录默认不存在,需要

自行创建



mkdir -p ~/.vim/after/ftplugin

mkdir -p ~/.vim/tools/pydiction/



cp pydiction-1.2/python_pydiction.vim ~/.vim/after/ftplugin/

cp pydiction-1.2/complete-dict ~/.vim/tools/pydiction/





或者



mkdir -p ~/.vim/after/ftplugin

mkdir -p /usr/share/vim/vim72/pydiction



cp pydiction-1.2/python_pydiction.vim ~/.vim/after/ftplugin/

cp pydiction-1.2/complete-dict /usr/share/vim/vim72/pydiction/complete-dict





然后修改vimrc文件



vi /etc/vim/vimrc(添加如下内容):





" pydiction 1.2 python auto complete

filetype plugin on

"autocmd FileType python

"set omnifunc=pythoncomplete

let g:pydiction_location='~/.vim/tools/pydiction/complete-dict'

let g:pydictionh_menu_height=20







这时,按Tab键就可以补全代码



四、安装NERD_TREE目录树



wget  

 

你可能感兴趣的:(python)