最近准备入门python,于是网上搜索mac下的开发工具,大多数文章推荐使用macvim,下面就给出下载地址和配置。
1.macvim 下载地址:https://github.com/macvim-dev/macvim/releases
2.下载 dmg完成后直接双击安装,将MacVim.app拖进application里面,mvim不用管,启动macvim的时候可能会出现未授权之类的提示,不必忧心,在系统设置->security&privacy->general下选择打开就可以了。至于mvim本来是要拷贝到~/usr/bin 里面的,我没有设置,因为mac os 10.11 没有权限向bin中写文件,所以不能将mvim拷贝到~/usr/bin里面,但是据说可以通过这个方法解决https://segmentfault.com/q/1010000003095378?_ea=301917,但是我没试过。最后弹出桌面上的macvim..
3.于是macvim安装完成,就等着配置python插件了。插件配置比较啰嗦。
网上搜索了很多介绍插件的文章,最后决定用vbundle。参考了一下两个链接
https://github.com/VundleVim/Vundle.vim
https://segmentfault.com/a/1190000003962806
总结上述我自己配置了一个文件
我配置的vimrc不是在~/.vimrc里面配置的,而是在 find->application->macvim->右击show package contents->contents->Resources->vim->vimrc,这里面改的,修改后的文件如下
" System vimrc file for MacVim
"
" Maintainer: Bjorn Winckler
" Last Change: Sat Aug 29 2009
set nocompatible
" The default for 'backspace' is very confusing to new users, so change it to a
" more sensible value. Add "set backspace&" to your ~/.vimrc to reset it.
set backspace+=indent,eol,start
" Disable localized menus for now since only some items are translated (e.g.
" the entire MacVim menu is set up in a nib file which currently only is
" translated to English).
set langmenu=none
set encoding=utf-8 "设置编码"
syntax on "语法高亮
set number "显示行号
set tabstop=4 "设置tab为四个空格
set softtabstop=4 "设置软tab为四个空格
set shiftwidth=4
set expandtab
" Enable folding 开启代码折叠
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar 代码折叠需要手动输入:za,这样设置以后就不用手动输入了,点一下空格就能实现折叠和展开
nnoremap
“ vbundle设置
set nocompatible " be iMproved, 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 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
"折叠插件
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-scripts/indentpython.vim'
let g:SimpylFold_docstring_preview=1
"一个不错的文件树形结构
Plugin 'scrooloose/nerdtree'
"如果你想用tab键
Plugin 'jistr/vim-nerdtree-tabs'
"想要在Vim中搜索任何文件?试试ctrlP插件吧:
Plugin 'kien/ctrlp.vim'
"自动补全 contrl+p能够关键字补全
Bundle 'Valloric/YouCompleteMe'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" "Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" "Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" 通过安装syntastic插件,每次保存文件时Vim都会检查代码的语法:
Plugin 'scrooloose/syntastic'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
"折叠设置
au BufNewFile,BufRead *.py
\ set tabstop=4
\ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
"标示不必要的空白字符
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
"第一行确保了在你完成操作之后,自动补全窗口不会消失,第二行则定义了“转到定义”的快捷方式。"
let g:ycm_autoclose_preview_window_after_completion=1
map
"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
"最后,让你的代码变得更漂亮:
let python_highlight_all=1
syntax on
好了就这些了,我还要继续研究如何方便使用。