mac10.11+vim rust开发环境搭建

mac10.11+vim rust开发环境搭建

1、安装rust

打开终端 输入如下命令
curl -sf -L https://static.rust-lang.org/rustup.sh | sh
命令行安装可能失败,请到 [rust官网]下载安装

安装完成后,输入以下命令
$ rustc –version
如果出现如下 :
rustc 1.3.0 (9a92aaf19 2015-09-15)(恭喜安装成功)

2、安装macvim

2.1、首先安装home-brew包管理工具

请参考 [我的Mac开发环境配置]

2.2、安装macvim

1.下载macvim:我的网盘分享macvim7.4 密码: fjtr
2.解压macvim:解压后三个文件
1)macvim(放入application文件夹);
2)mvim(放入/usr/local/bin);
[注] 方法一:终端命令:“cd /mvim文件路径“
“$sudo cp -f mvim /usr/local/bin/“
方法二:终端命令:”defaults write com.apple.finder AppleShowAllFiles -bool true” 打开显示隐藏文件
找到路径 /usr/local/bin, 将mivm文件复制于里面
终端命令:“defaults write com.apple.finder AppleShowAllFiles -bool false“ 关闭显示隐藏文件
3)readerme(看完删除)
3.打开macvim:方法一:终端命令:“mvim“
方法二:双击MacVim应用程序图标

3、配置macvim rust 开发环境

3.1、首先安装vim插件管理的一个插件vundle,详细用法请参考[github]

1) 在终端输入如下命令
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
2) 配置插件
在你的用户目录(Users/你的用户名)创建 .vimrc文件,添加下面配置内容

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'
" 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/'}
" Avoid a name conflict with L9
" Plugin 'user/L9', {'name': 'newL9'}

" 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

3)启动vim,执行:PluginInstall

3.2、安装rust.vim 插件,此插件提供文件检查和语法高亮功能

1) 在 ~/.vimrc 中Plugin ‘rust-lang/rust.vim’ (必须放在call vundle#begin() 和call vundle#end()之间 )
2) 执行命令 vim +PluginInstall +qall
详细请参考 https://github.com/VundleVim/Vundle.vim

3.3安装racer(详细请参考[phildawes/racer])

1) 打开终端,创建/usr/local/rust目录,命令如下
mkdir /usr/local/rust
进入/usr/local/rust目录,命令如下
cd /usr/local/rust
2) 安装racer 执行一下命令
git clone https://github.com/phildawes/racer.git //克隆库
cd racer //进入racer目录下
cargo build –release //编译生成二进制文件
编译结果放在 ./target/release/racer下
3)下载源码 https://www.rust-lang.org/install.html
我将源码放在了/usr/local/rust/src下
4)设置 RUST_SRC_PATH 源码所在目录 , 执行以下命令
export RUST_SRC_PATH=/usr/local/rust/src/rustc-1.3.0/src
5) 在命令行测试
./target/release/racer complete std::io::B

3.4 安装 vim-racer插件,补全提示功能(详细请参考[racer-rust/vim-racer])

1) 在 ~/.vimrc 中Plugin ‘racer-rust/vim-racer’ (必须放在call vundle#begin() 和call vundle#end()之间 )
2)执行命令 vim +PluginInstall +qall
3)添加 g:racer_cmd 和 $RUST_SRC_PATH 变量 到 ~/.vimrc

set hidden
let g:racer_cmd = "/usr/local/rust/racer/target/release/racer"
let $RUST_SRC_PATH="/usr/local/rust/src/rustc-1.3.0/src"

3.5 安装 Vim number toggle 提供显示绝对行号和相对行号(详细请参考[vim-numbertoggle])

1) 在 ~/.vimrc 中Plugin ‘git://github.com/jeffkreeftmeijer/vim-numbertoggle.git’ (必须放在call vundle#begin() 和call vundle#end()之间 )
2)执行命令 vim +PluginInstall +qall

3.6 安装 NERDtree 显示左侧问价菜单(详细请参考[NERDtree])

1) 在 ~/.vimrc 中Plugin ‘Plugin ‘https://github.com/scrooloose/nerdtree.git’ (必须放在call vundle#begin() 和call vundle#end()之间 )
2)执行命令 vim +PluginInstall +qall
3)用鼠标点击左侧菜单
在 ~/.vimrc 中添加以下配置代码

"enable mouse support
set mouse=a

3.7 贴上我简单的vim rust开发环境配置.vimrc文件

set nocompatible              " be iMproved, required
set number
"rust-racer
set hidden
let g:racer_cmd = "/usr/local/rust/racer/target/release/racer"
let $RUST_SRC_PATH="/usr/local/rust/src/rustc-1.3.0/src"
"nerdtree
autocmd VimEnter * NERDTree
autocmd BufEnter * NERDTreeMirror

"CTRL-t to toggle tree view with CTRL-t
nmap <silent> <C-t> :NERDTreeToggle<CR>
"Set F2 to put the cursor to the nerdtree
nmap   :NERDTreeFind
"enable mouse support
set mouse=a
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'

Plugin 'rust-lang/rust.vim'
Plugin 'racer-rust/vim-racer'
Plugin 'git://github.com/jeffkreeftmeijer/vim-numbertoggle.git'
Plugin 'https://github.com/scrooloose/nerdtree.git' 
" 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'
" 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/'}
" Avoid a name conflict with L9
"Plugin 'user/L9', {
    'name': 'newL9'}

" 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

本人主要参考 https://github.com/ivanceras/rust-vim-setup,如果英语好的,请直接看github上的

你可能感兴趣的:(rust,vim,rust,mac)