mac上安装macvim

首先咱们须要安装homebrew,在终端输入下面命令安装:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
//或者
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装完成后,运行下面代码安装vim和mac vim:html

brew install vim
brew install macvim
brew install ctags
brew install cscope

设置Mac上的ctage和默认的vim

如今已经安装了必备的软件了,可是Mac下Xcode也有一个程序叫ctags,并且mac也自带vim,因此咱们须要修改系统变量:git

sudo vim /etc/paths

系统默认将/usr/bin放在第一行,只须要将/usr/local/bin放在第一行就能够了:github

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

通过这样的配置,就可使用最新版的vim了。vim

用ctags和cscope解析代码

接下来在代码的根目录运行:ruby

ctags -R
cscope -Rbq

使用vundle自动安装相关插件并配置

首先须要安装vundle,不然会报错的curl

在用户目录下建立.vimrc文件  注意查看的时候要用ls -a 来查看隐藏文件函数

粘贴这段内容到.vimrc中:ui

"设置vundle
set nocompatible              " be iMproved
filetype off                  " required!

set rtp+=~/.vim/bundle/vundle/
call vundle##rc()

Bundle 'scrooloose/nerdtree'  "文件浏览
Bundle 'majutsushi/tagbar'    "代码符号
Bundle 'wesleyche/SrcExpl'    "相似sourceInsight的代码预览窗口
filetype plugin indent on     " required!
"vundle设置完毕

syntax on
let g:tagbar_ctags_bin='/usr/local/bin/ctags'
let g:tagbar_left = 1
nnoremap <F3> :TagbarToggle<CR>
let NERDTreeWinPos='right'
nnoremap <F2> :NERDTreeToggle<CR>
nmap <F4> :SrcExplToggle<CR>
let g:Srcexpl_winHeight = 8
" // Set 100 ms for refreshing the Source Explorer
let g:SrcExpl_refreshTime = 100

" // Set "Enter" key to jump into the exact definition context
let g:SrcExpl_jumpKey = "<ENTER>"

" // Set "Space" key for back from the definition context
let g:SrcExpl_gobackKey = "<SPACE>"

let g:SrcExpl_pluginList = [
         \ "__Tag_List__",
                 \ "_NERD_tree_"
                     \ ]


set tags=tags;/  "搜索上一级创建的tag



nmap <C-H> <C-W>h "control+h进入左边的窗口
nmap <C-J> <C-W>j  "control+j进入下边的窗口
nmap <C-K> <C-W>k "control+k进入上边的窗口
nmap <C-L> <C-W>l  "control+l进入右边的窗口

保存后,再使用vim后,发现报错,报错以下:url

 

Error detected while processing /Users/lizhiyong/.vimrc:spa

line    6:

E117: Unknown function: vundle##rc

line    8:

E492: Not an editor command: Bundle 'scrooloose/nerdtree'  "文件浏览

line    9:

E492: Not an editor command: Bundle 'majutsushi/tagbar'    "代码符号

line   10:

E492: Not an editor command: Bundle 'wesleyche/SrcExpl'    "相似sourceInsight的代码预览窗口

Press ENTER or type command to continue

 

提示的错误是在.vimrc中不认识vundle及Bundle这两个函数,解决办法就是安装vundle

 

vundle,基于Git仓库的插件管理软件。

vundle将插件的安装简化为相似yum软件安装的过程,只要:BundleInstall插件就安装完了,:BundleClean以后插件就卸载了。

更换机器时,在新机器上安装vundle并使用老的vundle配置,便可安装全部配置好的插件。

 

安装:

$ git clone http://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  

 

保存后,从新启动vim,按ESC后输入:BundleInstall后回车,系统会自动安装这些插件。

安装过程也比较诗意

安装完成后从新启动vim,这时按下F2,F3,F4,就看到比较新颖的东西了。若是在mac上执行F2 F3 F4是执行屏幕操做的话,那就配合使用fn键。