兵團基地

一起學習、共同進步。
兵團基地

从源码构建Vim

引言

事情是介样滴,因为我是个Vim 重度使用者了差不多。。

但在大部分系统上能安装到的或者自带的都是比较老的版本,可能是7.x 之类的。也或者是你需要使用到Vim 的某些特性或者功能,但别人帮你Build 好的程序并没有启用,这就很尴尬了。

所以,我们要从源代码自已构建自已的Vim.

步骤

下载运行时及源码

首先是要安装编译必要的库,这里你们看情况,有报错缺啥就补也成。

可能需要这些(我自已不用装就可以了):

sudo apt install ncurses-dev
 
 # or
 
 sudo apt install libncurses-dev
 
 # or
 
 sudo apt install libncurses5-dev \
                 libgtk2.0-dev \
                 libatk1.0-dev \
                 libcairo2-dev \
                 python-dev \
                 python3-dev \
                 git
 

然后是下载源码:

cd ~ && git clone https://github.com/vim/vim.git && cd vim/src
 

配置Vim

因为Vim 支持的功能非常多,所以你可以自已选需要的功能打开或者关闭。可以参看这里

也可以通过这个命令查看你当前的Vim 版本及功能的情况:

$ vim --version | less
 VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 19 2021 18:24:53)
 macOS version - x86_64
 Included patches: 1-2375
 Compiled by Homebrew
 Huge version without GUI.  Features included (+) or not (-):
 +acl               -farsi             +mouse_sgr         +tag_binary
 +arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
 +autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
 +autochdir         +float             +mouse_xterm       -tcl
 -autoservername    +folding           +multi_byte        +termguicolors
 -balloon_eval      -footer            +multi_lang        +terminal
 +balloon_eval_term +fork()            -mzscheme          +terminfo
 -browse            +gettext           +netbeans_intg     +termresponse
 ++builtin_terms    -hangul_input      +num64             +textobjects
 +byte_offset       +iconv             +packages          +textprop
 +channel           +insert_expand     +path_extra        +timers
 +cindent           +ipv6              +perl              +title
 -clientserver      +job               +persistent_undo   -toolbar
 +clipboard         +jumplist          +popupwin          +user_commands
 +cmdline_compl     +keymap            +postscript        +vartabs
 +cmdline_hist      +lambda            +printer           +vertsplit
 +cmdline_info      +langmap           +profile           +virtualedit
 +comments          +libcall           -python            +visual
 +conceal           +linebreak         +python3           +visualextra
 +cryptv            +lispindent        +quickfix          +viminfo
 +cscope            +listcmds          +reltime           +vreplace
 +cursorbind        +localmap          +rightleft         +wildignore
 +cursorshape       +lua               +ruby              +wildmenu
 +dialog_con        +menu              +scrollbind        +windows
 +diff              +mksession         +signs             +writebackup
 +digraphs          +modify_fname      +smartindent       -X11
 -dnd               +mouse             -sound             -xfontset
 -ebcdic            -mouseshape        +spell             -xim
 +emacs_tags        +mouse_dec         +startuptime       -xpm
 +eval              -mouse_gpm         +statusline        -xsmp
 +ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
 +extra_search      +mouse_netterm     +syntax            -xterm_save
    system vimrc file: "$VIM/vimrc"
      user vimrc file: "$HOME/.vimrc"
  2nd user vimrc file: "~/.vim/vimrc"
       user exrc file: "$HOME/.exrc"
        defaults file: "$VIMRUNTIME/defaults.vim"
   fall-back for $VIM: "/usr/local/share/vim"
 

上面第一行就写了版本号,而那些所有的特性就列在了下面,带 + 的是启用的了, - 号的是没启用。

如果没错的话现在我们在 vim/src 这个目录里了。

通过这个命令可以基本开启全功能:

./configure \
     --with-features=huge \
     --enable-multibyte \
     --enable-rubyinterp \
     --enable-perlinterp \
     --enable-luainterp \
     --enable-pythoninterp \
     --with-python-config-dir=/usr/lib/python2.7/config-arm-linux-gnueabihf/ \
     --enable-python3interp \
     --with-python3-config-dir=/usr/lib/python3.7/config-3.7m-arm-linux-gnueabihf/ \
     --enable-gui=gtk2 \
     --enable-cscope \
     --prefix=/usr
 

注意:里面两个Python 路径替换成你机器上的实际情况!

或者,你想关闭某个默认是开启的功能也可以用这样关掉:

./configure --enable-multibyte=no --enable-cscope=yes
 

直接写xxx=no 会关闭而xxx=yes 会开启,上面这条例子我们关了enable-multibyte, 而开启了enable-cscope.

如果要查看所有选项,也可以这样:

./configure --help
 

显示的内容中 Features 列表就是可选的功能。

...<more>
 
 Optional Features:                                                                                                                                                      [52/219]
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-fail-if-missing    Fail if dependencies on additional features
      specified on the command line are missing.
   --disable-darwin        Disable Darwin (Mac OS X) support.
   --disable-smack         Do not check for Smack support.
   --disable-selinux       Do not check for SELinux support.
   --disable-xsmp          Disable XSMP session management
   --disable-xsmp-interact Disable XSMP interaction
   --enable-luainterp=OPTS      Include Lua interpreter.  default=no OPTS=no/yes/dynamic
   --enable-mzschemeinterp      Include MzScheme interpreter.
   --enable-perlinterp=OPTS     Include Perl interpreter.  default=no OPTS=no/yes/dynamic
   --enable-pythoninterp=OPTS   Include Python interpreter. default=no OPTS=no/yes/dynamic
   --enable-python3interp=OPTS  Include Python3 interpreter. default=no OPTS=no/yes/dynamic
   --enable-tclinterp=OPTS      Include Tcl interpreter. default=no OPTS=no/yes/dynamic
   --enable-rubyinterp=OPTS     Include Ruby interpreter.  default=no OPTS=no/yes/dynamic
   --enable-cscope         Include cscope interface.
   --disable-netbeans      Disable NetBeans integration support.
   --disable-channel       Disable process communication support.
   --enable-terminal       Enable terminal emulation support.
   --enable-autoservername Automatically define servername at vim startup.
   --enable-multibyte      Include multibyte editing support.
   --disable-rightleft     Do not include Right-to-Left language support.
   --disable-arabic        Do not include Arabic language support.
   --disable-farsi         Deprecated.
   --enable-xim            Include XIM input support.
   --enable-fontset        Include X fontset output support.
   --enable-gui=OPTS       X11 GUI. default=auto OPTS=auto/no/gtk2/gnome2/gtk3/motif/athena/neXtaw/haiku/photon/carbon
   --enable-gtk2-check     If auto-select GUI, check for GTK+ 2 default=yes
   --enable-gnome-check    If GTK GUI, check for GNOME default=no
   --enable-gtk3-check     If auto-select GUI, check for GTK+ 3 default=yes
   --enable-motif-check    If auto-select GUI, check for Motif default=yes
   --enable-athena-check   If auto-select GUI, check for Athena default=yes
   --enable-nextaw-check   If auto-select GUI, check for neXtaw default=yes
   --disable-gtktest       Do not try to compile and run a test GTK program
   --disable-icon-cache-update        update disabled
   --disable-desktop-database-update  update disabled
   --disable-largefile     omit support for large files
   --disable-canberra      Do not use libcanberra.
   --disable-libsodium      Do not use libsodium.
   --disable-acl           No check for ACL support.
   --disable-gpm           Don't use gpm (Linux mouse daemon).
   --disable-sysmouse      Don't use sysmouse (mouse in *BSD console).
   --disable-nls           Don't support NLS (gettext()).
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-mac-arch=ARCH    current, intel, ppc or both
   --with-developer-dir=PATH    use PATH as location for Xcode developer tools
   --with-local-dir=PATH   search PATH instead of /usr/local for local libraries.
   --without-local-dir     do not search /usr/local for local libraries.
   --with-vim-name=NAME    what to call the Vim executable
   --with-ex-name=NAME     what to call the Ex executable
   --with-view-name=NAME   what to call the View executable
   --with-global-runtime=DIR    global runtime directory in 'runtimepath', comma-separated for multiple directories
   --with-modified-by=NAME       name of who modified a release version
   --with-features=TYPE    tiny, small, normal, big or huge (default: huge)
   --with-compiledby=NAME  name to show in :version message
   --with-lua-prefix=PFX   Prefix where Lua is installed.
   --with-luajit           Link with LuaJIT instead of Lua.
   --with-plthome=PLTHOME   Use PLTHOME.
   --with-python-command=NAME  name of the Python 2 command (default: python2 or python)
   --with-python-config-dir=PATH  Python's config directory (deprecated)
   --with-python3-command=NAME  name of the Python 3 command (default: python3 or python)
   --with-python3-config-dir=PATH  Python's config directory (deprecated)
   --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)
   --with-ruby-command=RUBY  name of the Ruby command (default: ruby)
   --with-x                use the X Window System
   --with-gnome-includes=DIR Specify location of GNOME headers
   --with-gnome-libs=DIR   Specify location of GNOME libs
   --with-gnome            Specify prefix for GNOME files
   --with-motif-lib=STRING Library for Motif
   --with-tlib=library     terminal library to be used
 
   ...<more>
 

命令运行后程序会跑很多checking, 耐心等待它跑完就行。

安装

在运行完configure 后,配置就设置好了,接下来就可以直接安装了。

make
 sudo make install
 

你想要也可以指定位置:

sudo make VIMRUNTIMEDIR=/usr/local/share/vim/vim82
 

或者指定最多可运行多少jobs 以防止小机器受不了,因为不限制它会随便开:

make -j 4
 

在跑完make 和install 命令后,vim 应该就已经安装好了。再次查看一下版本应该就是最新的了。

如果没有变化的话,可能是因为shell 的缓存机制导致的,可以另开一个shell 或者用下面的命令更新一下缓存:

hash vim
 

大功告成~

从源码构建Vim

引言

事情是介样滴,因为我是个Vim 重度使用者了差不多。。

但在大部分系统上能安装到的或者自带的都是比较老的版本,可能是7.x 之类的。也或者是你需要使用到Vim 的某些特性或者功能,但别人帮你Build 好的程序并没有启用,这就很尴尬了。

所以,我们要从源代码自已构建自已的Vim.

步骤

下载运行时及源码

首先是要安装编译必要的库,这里你们看情况,有报错缺啥就补也成。

可能需要这些(我自已不用装就可以了):

sudo apt install ncurses-dev
 
 # or
 
 sudo apt install libncurses-dev
 
 # or
 
 sudo apt install libncurses5-dev \
                 libgtk2.0-dev \
                 libatk1.0-dev \
                 libcairo2-dev \
                 python-dev \
                 python3-dev \
                 git
 

然后是下载源码:

cd ~ && git clone https://github.com/vim/vim.git && cd vim/src
 

配置Vim

因为Vim 支持的功能非常多,所以你可以自已选需要的功能打开或者关闭。可以参看这里

也可以通过这个命令查看你当前的Vim 版本及功能的情况:

$ vim --version | less
 VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jan 19 2021 18:24:53)
 macOS version - x86_64
 Included patches: 1-2375
 Compiled by Homebrew
 Huge version without GUI.  Features included (+) or not (-):
 +acl               -farsi             +mouse_sgr         +tag_binary
 +arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
 +autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
 +autochdir         +float             +mouse_xterm       -tcl
 -autoservername    +folding           +multi_byte        +termguicolors
 -balloon_eval      -footer            +multi_lang        +terminal
 +balloon_eval_term +fork()            -mzscheme          +terminfo
 -browse            +gettext           +netbeans_intg     +termresponse
 ++builtin_terms    -hangul_input      +num64             +textobjects
 +byte_offset       +iconv             +packages          +textprop
 +channel           +insert_expand     +path_extra        +timers
 +cindent           +ipv6              +perl              +title
 -clientserver      +job               +persistent_undo   -toolbar
 +clipboard         +jumplist          +popupwin          +user_commands
 +cmdline_compl     +keymap            +postscript        +vartabs
 +cmdline_hist      +lambda            +printer           +vertsplit
 +cmdline_info      +langmap           +profile           +virtualedit
 +comments          +libcall           -python            +visual
 +conceal           +linebreak         +python3           +visualextra
 +cryptv            +lispindent        +quickfix          +viminfo
 +cscope            +listcmds          +reltime           +vreplace
 +cursorbind        +localmap          +rightleft         +wildignore
 +cursorshape       +lua               +ruby              +wildmenu
 +dialog_con        +menu              +scrollbind        +windows
 +diff              +mksession         +signs             +writebackup
 +digraphs          +modify_fname      +smartindent       -X11
 -dnd               +mouse             -sound             -xfontset
 -ebcdic            -mouseshape        +spell             -xim
 +emacs_tags        +mouse_dec         +startuptime       -xpm
 +eval              -mouse_gpm         +statusline        -xsmp
 +ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
 +extra_search      +mouse_netterm     +syntax            -xterm_save
    system vimrc file: "$VIM/vimrc"
      user vimrc file: "$HOME/.vimrc"
  2nd user vimrc file: "~/.vim/vimrc"
       user exrc file: "$HOME/.exrc"
        defaults file: "$VIMRUNTIME/defaults.vim"
   fall-back for $VIM: "/usr/local/share/vim"
 

上面第一行就写了版本号,而那些所有的特性就列在了下面,带 + 的是启用的了, - 号的是没启用。

如果没错的话现在我们在 vim/src 这个目录里了。

通过这个命令可以基本开启全功能:

./configure \
     --with-features=huge \
     --enable-multibyte \
     --enable-rubyinterp \
     --enable-perlinterp \
     --enable-luainterp \
     --enable-pythoninterp \
     --with-python-config-dir=/usr/lib/python2.7/config-arm-linux-gnueabihf/ \
     --enable-python3interp \
     --with-python3-config-dir=/usr/lib/python3.7/config-3.7m-arm-linux-gnueabihf/ \
     --enable-gui=gtk2 \
     --enable-cscope \
     --prefix=/usr
 

注意:里面两个Python 路径替换成你机器上的实际情况!

或者,你想关闭某个默认是开启的功能也可以用这样关掉:

./configure --enable-multibyte=no --enable-cscope=yes
 

直接写xxx=no 会关闭而xxx=yes 会开启,上面这条例子我们关了enable-multibyte, 而开启了enable-cscope.

如果要查看所有选项,也可以这样:

./configure --help
 

显示的内容中 Features 列表就是可选的功能。

...<more>
 
 Optional Features:                                                                                                                                                      [52/219]
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --enable-fail-if-missing    Fail if dependencies on additional features
      specified on the command line are missing.
   --disable-darwin        Disable Darwin (Mac OS X) support.
   --disable-smack         Do not check for Smack support.
   --disable-selinux       Do not check for SELinux support.
   --disable-xsmp          Disable XSMP session management
   --disable-xsmp-interact Disable XSMP interaction
   --enable-luainterp=OPTS      Include Lua interpreter.  default=no OPTS=no/yes/dynamic
   --enable-mzschemeinterp      Include MzScheme interpreter.
   --enable-perlinterp=OPTS     Include Perl interpreter.  default=no OPTS=no/yes/dynamic
   --enable-pythoninterp=OPTS   Include Python interpreter. default=no OPTS=no/yes/dynamic
   --enable-python3interp=OPTS  Include Python3 interpreter. default=no OPTS=no/yes/dynamic
   --enable-tclinterp=OPTS      Include Tcl interpreter. default=no OPTS=no/yes/dynamic
   --enable-rubyinterp=OPTS     Include Ruby interpreter.  default=no OPTS=no/yes/dynamic
   --enable-cscope         Include cscope interface.
   --disable-netbeans      Disable NetBeans integration support.
   --disable-channel       Disable process communication support.
   --enable-terminal       Enable terminal emulation support.
   --enable-autoservername Automatically define servername at vim startup.
   --enable-multibyte      Include multibyte editing support.
   --disable-rightleft     Do not include Right-to-Left language support.
   --disable-arabic        Do not include Arabic language support.
   --disable-farsi         Deprecated.
   --enable-xim            Include XIM input support.
   --enable-fontset        Include X fontset output support.
   --enable-gui=OPTS       X11 GUI. default=auto OPTS=auto/no/gtk2/gnome2/gtk3/motif/athena/neXtaw/haiku/photon/carbon
   --enable-gtk2-check     If auto-select GUI, check for GTK+ 2 default=yes
   --enable-gnome-check    If GTK GUI, check for GNOME default=no
   --enable-gtk3-check     If auto-select GUI, check for GTK+ 3 default=yes
   --enable-motif-check    If auto-select GUI, check for Motif default=yes
   --enable-athena-check   If auto-select GUI, check for Athena default=yes
   --enable-nextaw-check   If auto-select GUI, check for neXtaw default=yes
   --disable-gtktest       Do not try to compile and run a test GTK program
   --disable-icon-cache-update        update disabled
   --disable-desktop-database-update  update disabled
   --disable-largefile     omit support for large files
   --disable-canberra      Do not use libcanberra.
   --disable-libsodium      Do not use libsodium.
   --disable-acl           No check for ACL support.
   --disable-gpm           Don't use gpm (Linux mouse daemon).
   --disable-sysmouse      Don't use sysmouse (mouse in *BSD console).
   --disable-nls           Don't support NLS (gettext()).
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-mac-arch=ARCH    current, intel, ppc or both
   --with-developer-dir=PATH    use PATH as location for Xcode developer tools
   --with-local-dir=PATH   search PATH instead of /usr/local for local libraries.
   --without-local-dir     do not search /usr/local for local libraries.
   --with-vim-name=NAME    what to call the Vim executable
   --with-ex-name=NAME     what to call the Ex executable
   --with-view-name=NAME   what to call the View executable
   --with-global-runtime=DIR    global runtime directory in 'runtimepath', comma-separated for multiple directories
   --with-modified-by=NAME       name of who modified a release version
   --with-features=TYPE    tiny, small, normal, big or huge (default: huge)
   --with-compiledby=NAME  name to show in :version message
   --with-lua-prefix=PFX   Prefix where Lua is installed.
   --with-luajit           Link with LuaJIT instead of Lua.
   --with-plthome=PLTHOME   Use PLTHOME.
   --with-python-command=NAME  name of the Python 2 command (default: python2 or python)
   --with-python-config-dir=PATH  Python's config directory (deprecated)
   --with-python3-command=NAME  name of the Python 3 command (default: python3 or python)
   --with-python3-config-dir=PATH  Python's config directory (deprecated)
   --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)
   --with-ruby-command=RUBY  name of the Ruby command (default: ruby)
   --with-x                use the X Window System
   --with-gnome-includes=DIR Specify location of GNOME headers
   --with-gnome-libs=DIR   Specify location of GNOME libs
   --with-gnome            Specify prefix for GNOME files
   --with-motif-lib=STRING Library for Motif
   --with-tlib=library     terminal library to be used
 
   ...<more>
 

命令运行后程序会跑很多checking, 耐心等待它跑完就行。

安装

在运行完configure 后,配置就设置好了,接下来就可以直接安装了。

make
 sudo make install
 

你想要也可以指定位置:

sudo make VIMRUNTIMEDIR=/usr/local/share/vim/vim82
 

或者指定最多可运行多少jobs 以防止小机器受不了,因为不限制它会随便开:

make -j 4
 

在跑完make 和install 命令后,vim 应该就已经安装好了。再次查看一下版本应该就是最新的了。

如果没有变化的话,可能是因为shell 的缓存机制导致的,可以另开一个shell 或者用下面的命令更新一下缓存:

hash vim
 

大功告成~

兵团基地
Power by React, GraphQL | Design by Puls Garney | Version: 3.1.6
Copyright © 2017-2024 Puls Garney - All Rights Reserved.
Power by React, GraphQL
Design by Puls Garney
Version: 3.1.6

Copyright © 2017-2024 Puls Garney
All Rights Reserved.