將VIM打造為python IDE


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 nocompatible
filetype plugin on
colorscheme lucius
set number
syntax on 
syntax enable
set autoindent
set smartindent
set 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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM