您的位置:首页 > 其它

vim

2016-06-20 16:30 204 查看

学而时记之,不易忘乎.忘而再寻之,不易慢乎.

博客园
首页
新随笔
联系
订阅
管理

随笔 - 19  文章 - 2  评论 - 1

2015年2月1日

Mac
Yosemite上安装macvim和YouCompleteMe

今天在macvim上安装YouCompleteMe的时候,碰到一个运行vim崩溃的错误.查了半天终于解决!

先上一下安装macvim的过程

# install xcode and command line tools
$ xcode-select --install
# install homebrew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # install python
$ brew install python
# install macvim
$ brew install macvim


然后编辑.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 'gmarik/Vundle.vim'

Plugin 'altercation/vim-colors-solarized'
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'kien/ctrlp.vim'
Plugin 'scrooloose/syntastic'
Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required


在vim中运行命令

:BundleInstall

完成后进入目录中

cd ~/.vim/bundle/YouCompleteMe
./install.sh --clang-completer


编译完成后,运行vim结果出错.

$ vim
Vim: Caught deadly signal ABRT
Vim: Finished.
Abort trap: 6


查了一圈发现,加一个参数后能正常工作

$ DYLD_FORCE_FLAT_NAMESPACE=1 vim


但毕竟这不是一个办法,最后在github上的issue页面上看到问题的解决办法:

brew unlink python


运行后依然无效!!!!崩溃!!!

然后继续看下去

$ otool -L /usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/MacOS/Vim | grep -i python
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.6)


而我的系统上默认的python是2.7.9,而且路径为/Library/Frameworks/Python.framework/Versions/2.7/python!

OK找到问题所在了,现在的任务就是需要把这两个Python的版本调整成为一致!!!!

HOW to do it? Google之找到办法,把所有的操作整理到一起给大家:

sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7
sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc /usr/bin/pydoc
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config /usr/bin/python-config


需要详细解释的童鞋,可以查看这篇文档.

执行这段shell之后,需要编辑~/.bash_profile将系统默认的Python路径指向/System/Library这个文件夹

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH


改变Python版本后,执行vim就不再出现段错误了.

 

参考文献:

1. github issue#8

2. installing-homebrew-macvim-with-youcompleteme-on-yosemite 

3. Installing / Updating Python on OS X

 下面是自己碰到的觉得有必要说一下:

http://geek.csdn.net/news/detail/34295,我选择第二个

1、bundle的安装:

* install bundle:

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

* Installing needed plugins

:BundleInstall

安装好后,可以查看vim ~/.vim/bundle/bundle.vim,如下:



2、youcompleteme安装和编译:

在vim ~/.vim/bundle/bundle.vim加上一行Plugin 'Valloric/YouCompleteMe',再一次:BundleInstall >代表正在安装,安装好后 ,terminal运行

./install.sh --clang-completer命令,如果编译不了报错就去home-brew install提示相应的文件

你需要添加脚本YouCompleteMe如果没有权限添加不了的话,就的更改文件读写权限,r:4 w:2 x:1,用命令chmod 775  文件名修改权限,如果不行就open youcompleteme

这个文件,然后在右键:显示简介

这里修改权限,编译好后.ycm_extra_conf.py文件就是youcompleteme编译

后的文件,然后去vimrc里面配置正确的路劲,在terminal :find ~/ -name .ycm_extra_conf.py,如下



搜索相印的路径后,随便填入一个安装好后的路径,

在~/.vim/vimrc文件中添加:

let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' 

然后保存退出,如果没有添加会在vim进入的时候提示错误

3、出现这个是什么问题?



这是在root权限也就是全局修改vim的配置,这里我只修改了个人环境变量的,所以这个错没关系,但是:


这样的错,最简单你不知道改就进入
vim ~/.vim/vimrc里面修改相印的行242-246的那几行前面全部加上",把它们全部屏蔽先运行没错再说。

4、修改color 光标主题配置,因为我选的是第二种,他的主题有很多,如下:



我们要在vim ~/.vim/vimrc里面修改:



对比就是如下



修改后的:



把color solarized这个改成:color + 主题,也就是这个solarized变成上图绿色的那一部分,保存后再推出。

5、vimrc一定要在~/.vim/vimdc吗?

一定要,因为你如果要配置当前用户必须要~,如果是所有用户全局性的可能地址/users/用户名/.vim/vimrc,如果不知道地址可以在vim编辑命令:

system vimrc file: “$VIM\vimrc”

user vimrc file: “$HOME\_vimrc”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  博客