set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" Add all your plugins here (note older versions of Vundle used Bundle instead of Plugin)
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
缓存可以理解为最近打开的文件,vim提供了方便访问最近的缓存,只要输入:b <buffer name or number>用于切换到一个打开的缓存。可以使用:ls来列出所有缓存。
在:ls输出到最后,vim提示Hit enter to continue,你可以代之以:b <buffer number>来选择列表中的缓存。
代码目录
很多现代的IDE提供一个方便的折叠方式展示方法或者类,你可以在.vimrc中添加
" Enable folding
set foldmethod=indent
set foldlevel=99
但是这会是你必须使用za来进入目录,可以添加以下配置到.vimrc这样空格键就更好使用
" Enable folding with the spacebar
nnoremap <space> za
对于初始化命令,使用 set foldmethod=indent,创建行缩进的目录,这样可以更为方便。比较好的推荐插件是SimpylFold,可以在 .vimrc 中添加
Plugin 'tmhedberg/SimpylFold'
然后再次执行 :PluginInstall 就可以安装插件
然后在.vimrc中添加
let g:SimpylFold_docstring_preview=1
Python缩排
对于Python,缩排是非常重要的,需要满足如下两点来完成缩进
缩进符合PEP8标准
自动处理缩进
在 .vimrc 中添加
au BufNewFile,BufRead *.py
\ set tabstop=4
\ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
然后再添加以下内容
au BufNewFile,BufRead *.js, *.html, *.css
\ set tabstop=2
\ set softtabstop=2
\ set shiftwidth=2
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
UTF8支持
在.vimrc中添加
set encoding=utf-8
自动完成
一个非常好的自动完成插件 Valloric/YouCompleteMe,也就是添加
Bundle 'Valloric/YouCompleteMe'
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
此外,如果提示错误:
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM before using it. Read the docs!
这个报错是正常的,因为ycm需要手工编译出库文件
cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer
支持Virtualenv
"python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF