Build Vim from source code

The introduction

It’s the same thing, because I’m a Vim heavy user.

But on most systems, the one you can install or ship with is an older version, maybe something like 7.x. Or maybe you need to use some of the features or features of Vim, but someone else built the application for you and it’s not enabled, which can be embarrassing.

So, we’ll build our own Vim from source code.

steps

Download the runtime and source code

The first is to install and compile the necessary library, here you see the situation, there is a report error missing what to fill also become.

You may need these (I don’t have to install them myself) :

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

Then download the source code:

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

Configuration of Vim

Because Vim supports so many features, you can turn them on or off by yourself. You can see it here

You can also check your current Vim version and functionality with this command:

$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"

The version number is written on the top line, and all the features are listed below, with + being enabled and – being not enabled.

If that’s right now we’re in the vim/ SRC directory.

With this command, you can basically turn on the full function:

./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.7 - m - arm - Linux - gnueabihf / \ --enable-gui=gtk2 \ --enable-cscope \ --prefix=/usr

Note: There are two Python paths that replace the actual conditions on your machine!

Or, if you want to turn off a feature that is enabled by default, you can turn it off like this:

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

Writing XXX =no will turn it off and XXX =yes will turn it on. In the example above we have enable-multibyte turned off and enable-cscope turned on.

After the command is run, the program will run a number of checking, waiting patiently for it to finish.

The installation

After running configure, the configuration is set up and you’re ready to install directly.

make
sudo make install

You can also specify the location if you want:

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

Or specify a maximum number of jobs to run in case the small machine is overwhelmed, since there is no limit on how many jobs it can run:

make -j 4

After running the make and install commands, Vim should be installed. A second look at the version should be the latest.

If there is no change, it may be caused by the shell’s caching mechanism. You can either open a new shell or update the cache with the following command:

hash vim

We’re done