Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active February 16, 2026 12:46
Show Gist options
  • Select an option

  • Save Konfekt/d487ad78697f334eb8dfaa252fc6fa85 to your computer and use it in GitHub Desktop.

Select an option

Save Konfekt/d487ad78697f334eb8dfaa252fc6fa85 to your computer and use it in GitHub Desktop.
Compile Vim from source with dynamic Python 3 support for virtual environments
#!/usr/bin/env bash
# trace exit on error of program or pipe (or use of undeclared variable)
set -o errtrace -o errexit -o pipefail # -o nounset
# optionally debug output by supplying TRACE=1
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
if [[ "${BASH_VERSINFO:-0}" -gt 4 || ( "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ) ]]; then
shopt -s inherit_errexit
fi
PS4='+\t '
[[ ! -t 0 ]] && [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]] && command -v notify-send > /dev/null 2>&1 && notify=1
error_handler() {
summary="Error: In ${BASH_SOURCE[0]}, Lines $1 and $2, Command $3 exited with Status $4"
body=$(pr -tn "${BASH_SOURCE[0]}" | tail -n+$(($1 - 3)) | head -n7 | sed '4s/^\s*/>> /')
echo >&2 -en "$summary\n$body"
[ -z "${notify:+x}" ] || notify-send --urgency=critical "$summary" "$body"
exit "$4"
}
trap 'error_handler $LINENO "$BASH_LINENO" "$BASH_COMMAND" $?' ERR
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo "Compile Vim from source with Python 3 support using uv-managed Python."
echo "Usage: $0"
exit
fi
main() {
# # On Debian/Ubuntu 22.04, install dependencies for building huge Vim:
# # Either install build-essential and git, and then use apt build-dep ...
# # sudo apt install build-essential git && sudo apt build-dep vim-gtk3
# # ... or install the dependencies directly:
# sudo apt install -y \
# autoconf cscope debhelper-compat libacl1-dev libcanberra-dev libgpm-dev \
# libgtk-3-dev libncurses-dev libselinux1-dev libsodium-dev libtool-bin \
# libxaw7-dev libxpm-dev libxt-dev procps
# # Install language support dependencies for Python 3, Ruby, Perl, Tcl, Lua:
# sudo apt update
# sudo apt install -y \
# libncursesw5-dev \
# python3-dev ruby-dev libperl-dev tcl-dev \
# lua5.2 liblua5.2-dev luajit libluajit-5.1-dev \
make distclean "-j$(nproc)" 2>/dev/null || true
# use python3-config to get python3 version:
PY_VERSION=$(python3-config --configdir | sed 's/.*python\([0-9]\+\.[0-9]\+\).*/\1/')
echo "Python 3 version: $PY_VERSION"
PY_CONFIG_DIR=$(python3-config --configdir)
echo "Python 3 config dir: $PY_CONFIG_DIR"
./configure \
--with-features=huge \
--enable-multibyte \
--enable-cscope \
--enable-gui=gtk3 \
--enable-xim \
--enable-fontset \
--enable-rubyinterp=dynamic \
--enable-perlinterp=dynamic \
--enable-luainterp=dynamic \
--with-luajit \
--enable-python3interp=dynamic \
--with-python3-config-dir="$PY_CONFIG_DIR" \
--with-python3-stable-abi="$PY_VERSION" \
--enable-tclinterp=dynamic \
--prefix=/usr/local \
--enable-fail-if-missing
# To set runtime dir, get vim version, say 92, from src/version.h
VIM_VERSION=$(awk '/^#define VIM_VERSION_MAJOR\>/ {major=$3} /^#define VIM_VERSION_MINOR\>/ {minor=$3} END {print major minor}' src/version.h)
echo "VIM version: $VIM_VERSION"
make VIMRUNTIMEDIR="/usr/local/share/vim/vim${VIM_VERSION}" --jobs="$(nproc)"
sudo make install PREFIX=/usr/local
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment