Date Tags vim

因为想在Vim中使用YouCompleteMe插件,但又不想把系统的vim弄脏了,所以还是得自己 编译一套。

编译Console版的Vim

从官网下载最新得Vim, http://www.vim.org/sources.php

解压 tar xf vim-7.4.tar.bz2

7.4 编译的时候有bug, 具体信息如下

os_unix.c:830:46: warning: declaration of 'struct sigaltstack' will not be visible outside of this function [-Wvisibility]
    extern int sigaltstack __ARGS((const struct sigaltstack *ss, struct sigaltstack *oss));

需要patch, vi src/os_unix.c

diff -r c1170f618303 src/os_unix.c
--- a/src/os_unix.c     Fri Jun 14 22:48:54 2013 +0200
+++ b/src/os_unix.c     Sat Jun 15 09:04:55 2013 -0500
@@ -827,7 +827,7 @@
                || MAC_OS_X_VERSION_MAX_ALLOWED <= 1040)
        /* missing prototype.  Adding it to osdef?.h.in doesn't work, because
         * "struct sigaltstack" needs to be declared. */
-       extern int sigaltstack __ARGS((const struct sigaltstack *ss, struct sigaltstack *oss));
+       extern int sigaltstack __ARGS((const stack_t *restrict ss, stack_t *restrict oss));
 #  endif

configure 命令参数如下

LD_LIBRARY_PATH=/apps/ide/vim/py/lib \
PATH=/apps/ide/vim/py/bin:$PATH \
./configure \
    --with-features=normal --enable-cscope --enable-pythoninterp \
    --with-python-config-dir=/apps/ide/vim/py/lib/python2.7/config \
    --prefix=/apps/ide/vim
vi ./src/auto/config.mk

CFLAGS      = -g -O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
PYTHON_LIBS     = -L/apps/ide/vim/py/lib -lpython2.7
PYTHON_GETPATH_CFLAGS = -DPYTHONPATH='":/apps/ide/vim/py/lib/python2.7/site-packages/setuptools-5.4.1-py2.7.egg:/apps/ide/vim/py/lib/python2.7:/apps/ide/vim/py/lib/python2.7/site-packages"' -DPREFIX='"/apps/ide/vim/py"' -DEXEC_PREFIX='"/apps/ide/vim/py"'
make -j4

测试python是否用自己编译的, vim中输入

:python import sys; print sys.path

YouCompleteMe:

/apps/ide/vim/bundle/YouCompleteMe
git submodule update --init --recursive
vi ./third_party/ycmd/build.sh
------
cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=/apps/dev/clang+llvm-3.4.2-x86_64-apple-darwin10.9 -DPYTHON_LIBRARY=/apps/ide/vim/py/lib/libpython2.7.dylib -DPYTHON_INCLUDE_DIR=/apps/ide/vim/py/include/python2.7 "$@" . "${SCRIPT_DIR}/cpp"
------
./install.sh --clang-completer

因为python只自己编译的python, 要在调用之前使用一下参数才不会出错

alias vi='DYLD_FORCE_FLAT_NAMESPACE=1 /apps/ide/vim/bin/vim'

编译GUI版的 mac vim

git clone git://github.com/b4winckler/macvim.git
cd macvim/src

LD_LIBRARY_PATH=/apps/ide/vim/py/lib \
PATH=/apps/ide/vim/py/bin:$PATH \
./configure \
    --with-features=normal --enable-cscope --enable-pythoninterp \
    --with-python-config-dir=/apps/ide/vim/py/lib/python2.7/config \
    --prefix=/apps/ide/vim
vi auto/config.mk

CFLAGS      = -g -O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
PYTHON_LIBS     = -L/apps/ide/vim/py/lib -lpython2.7
PYTHON_GETPATH_CFLAGS = -DPYTHONPATH='":/apps/ide/vim/py/lib/python2.7/site-packages/setuptools-5.4.1-py2.7.egg:/apps/ide/vim/py/lib/python2.7:/apps/ide/vim/py/lib/python2.7/site-packages"' -DPREFIX='"/apps/ide/vim/py"' -DEXEC_PREFIX='"/apps/ide/vim/py"'
make -j4

cp -r MacVim/build/Release/MacVim.app /apps/ide/vim/
cp MacVim/mvim /apps/ide/vim/

添加alias到bash_profile

vi ~/.bash_profile

alias mvim='DYLD_FORCE_FLAT_NAMESPACE=1 /apps/ide/vim/mvim'

参考:

  • https://github.com/Valloric/YouCompleteMe/issues/8
  • https://github.com/Valloric/YouCompleteMe/issues/18
  • https://gist.github.com/vishvananda/4717499
  • https://github.com/b4winckler/macvim/wiki/Building