苹果电脑下怎么安装vim

2025-02-24 00:40:12
推荐回答(2个)
回答1:

首先我们需要安装homebrew,在终端输入下面命令安装:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

安装完成后,运行下面代码安装vim和mac vim:
brew install vim
brew install macvim
brew install ctags
brew install cscope

设置Mac上的ctage和默认的vim
现在已经安装了必备的软件了,但是Mac下Xcode也有一个程序叫ctags,而且mac也自带vim,所以我们需要修改系统变量:
sudo vim /etc/paths

系统默认将/usr/bin放在第一行,只需要将/usr/local/bin放在第一行就可以了:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

经过这样的配置,就可以使用最新版的vim了。
用ctags和cscope解析代码
接下来在代码的根目录运行:
ctags -R
cscope -Rbq

使用vundle自动安装相关插件并配置
首先需要安装vundle,否则会报错的
在用户目录下创建.vimrc文件 注意查看的时候要用ls -a 来查看隐藏文件
粘贴这段内容到.vimrc中:
"设置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 :TagbarToggle
let NERDTreeWinPos='right'
nnoremap :NERDTreeToggle
nmap :SrcExplToggle
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 = ""

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

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

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

nmap h "control+h进入左边的窗口
nmap j "control+j进入下边的窗口
nmap k "control+k进入上边的窗口
nmap l "control+l进入右边的窗口

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

Error detected while processing /Users/lizhiyong/.vimrc:
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后回车,系统会自动安装这些插件。
安装过程也比较诗意

回答2:

您好,我看到您的问题很久没有人来回答,但是问题过期无人回答会被扣分的并且你的悬赏分也会被没收!所以我给你提几条建议:

一,你可以选择在正确的分类下去提问,这样知道你问题答案的人才会多一些,回答的人也会多些。

二,您可以到与您问题相关专业网站论坛里去看看,那里聚集了许多专业人才,一定可以为你解决问题的。

三,你可以向你的网上好友问友打听,他们会更加真诚热心为你寻找答案的,甚至可以到相关网站直接搜索.

四,网上很多专业论坛以及知识平台,上面也有很多资料,我遇到专业性的问题总是上论坛求解决办法的。

五,将你的问题问的细一些,清楚一些!让人更加容易看懂明白是什么意思!