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
