您的位置:首页 > 编程语言 > Python开发

将VIM打造为python IDE

2013-02-14 23:36 453 查看
1、编译安装VIM

gvim7.3是支持python的,但vim7.3却没有,因此要编译安装vim源代码来增加python的支持。

(1)安装依赖包

1.安装前要先用 apt-get install python-dev 安装python-dev 包,否则在make VIM源码时会报


error: Python.h: No such file or directory


的错误。

安装完python-dev 包后,/usr/lib/python2.6/config 下就会增加了很多文件

2.安装libncurses5-dev

apt-get install libncurses5-dev



3.安装xorg-dev(clipboard的支持需要)、libgtk2.0-dev(clipboard的支持需要,貌似不装也可以)

apt-get install xorg-dev

apt-get install libgtk2.0-dev

(2)修改Makefile文件

下载vim 7.3 源码,解压后转到vim-7.3/src目录下,打开Makefile,找到以下行:


#CONF_OPT_PYTHON = --enable-pythoninterp


把#号去掉以便编译时在vim里启用python

(3)运行configure

解压vim源码后,进入vim7.3/src 目录,运行:


./configure --with-features=huge --enable-multibyte --enable-xim --with-x --enable-pythoninterp=yes --enable-cscope --enable-fontset --enable-perlinterp --with-python-config-dir=/usr/lib/python2.6/config


然后make && make install

2、安装ctags插件

(1) 解压源码后执行


./configure && make && make install


(2)编辑~/.vimrc,加入以下行


set tags=tags;
set autochdir



3、安装taglist插件

(1)解压源码后,将doc及plugin文件夹分别放到vim73下的doc及plugin中

(2)编辑~/.vimrc,加入以下行


let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Process_File_Always=1


4、安装winmanager插件

(1)解压源码后,将doc及plugin文件夹分别放到vim73下的doc及plugin中

(2)编辑~/.vimrc,加入以下行


let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
let g:persistentBehaviour=0


5、安装MiniBufferExplorer插件

(1)解压源码后,将minibufexpl.vim放到vim73下的plugin中

(2)编辑~/.vimrc,加入以下行


let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowsNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplorerMoreThanOne=0


6、安装pydiction插件

(1)解压源码后,将里面的python_pydiction.vim、complete-dict、pydiction.py文件复制到 ~/.vim/after/ftplugin/ 路径下,如果这个路径不存在,可以自己创建这个文件夹结构。

(2)编辑~/.vimrc,加入以下行


let g:pydiction_location = '~/.vim/after/ftplugin/complete-dict'
autocmd FileType py set shiftwidth=4 | set expandtab


7、安装pyflakes插件

(1)解压源码后把pyflakes.vim文件和pyflakes目录拷贝到ftplugin\python目录中

8、安装vim-debug插件

(1)安装setuptools (安装pip要用到)


wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install


(2)下载pip-1.2.1.tar.gz,解压后执行:


python setup.py install


(3)下载vim-debug(http://jaredforsyth.com/projects/vim-debug/),执行:


pip install dbgp

pip install vim-debug

python install-vim-debug.py


(4)编辑~/.vimrc,加入以下快捷键


map <F5> :Dbg into<CR>
map <F6> :Dbg over<CR>
map <F7> :Dbg out<CR>
map <F8> :Dbg run<CR>
map <F9> :Dbg break<CR>
map <F10> :Dbg eval<CR>
map <F11> :Dbg .<CR>
map <F12> :Dbg quit<CR>



附上~/.vimrc文件:


source $VIMRUNTIME/vimrc_example.vim
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

set nocompatiblefiletype plugin oncolorscheme luciusset numbersyntax on syntax enableset autoindentset smartindentset t_Co=256" 输入字符串就显示匹配点 set incsearch

"""""""""""""""""""""""""""" " PEP8 " """""""""""""""""""""""""""":set textwidth=79:set tabstop=4

""""""""""""""""""""""""""""
" keys "
""""""""""""""""""""""""""""
map <F4> :q!<cr>
map <F3> :qa<cr>
""""""""""""""""""""""""""""
" pydiction "
""""""""""""""""""""""""""""
let g:pydiction_location = '~/.vim/ftplugin/complete-dict'
"在代码使用4个空格代替TAB符
autocmd FileType py set shiftwidth=4 | set expandtab

""""""""""""""""""""""""""""
" CTags "
""""""""""""""""""""""""""""
set tags=tags;
set autochdir
""""""""""""""""""""""""""""
" TagList "
""""""""""""""""""""""""""""
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Process_File_Always=1
""""""""""""""""""""""""""""
" WinManager "
""""""""""""""""""""""""""""
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
let g:persistentBehaviour=0
""""""""""""""""""""""""""""
" MiniBufferExplorer "
""""""""""""""""""""""""""""
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowsNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplorerMoreThanOne=0
""""""""""""""""""""""""""""
" vim-debug "
""""""""""""""""""""""""""""
map <F5> :Dbg into<CR>
map <F6> :Dbg over<CR>
map <F7> :Dbg out<CR>
map <F8> :Dbg run<CR>
map <F9> :Dbg break<CR>
map <F10> :Dbg eval<CR>
map <F11> :Dbg .<CR>
map <F12> :Dbg quit<CR>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: