← Back to vim/vim

How to Deploy & Use vim/vim

# Vim Deploy and Usage Guide

## 1. Prerequisites

### Build Requirements (Source Installation)
- **C compiler**: GCC, Clang, or MSVC (Windows)
- **Make**: GNU Make or BSD Make
- **ncurses/terminfo**: `libncurses5-dev` or `ncurses-devel` (Unix/Linux)
- **Git**: For cloning the repository

### Optional Dependencies (Feature Support)
- **GTK 2/3**: For GUI support (Gvim) on Unix
- **Python 3**: `--enable-python3interp` (requires python3-dev)
- **Lua**: `--enable-luainterp`
- **Perl**: `--enable-perlinterp`
- **Ruby**: `--enable-rubyinterp`
- **Tcl**: `--enable-tclinterp`

### Runtime Requirements
- Terminal with color support (xterm-256color recommended)
- POSIX-compliant shell (for external commands)
- `diff` utility (for diff mode)

## 2. Installation

### Method A: Package Manager (Recommended)
```bash
# Debian/Ubuntu
sudo apt-get install vim-gtk3   # GUI version
sudo apt-get install vim-nox    # Enhanced terminal version

# RHEL/CentOS/Fedora
sudo dnf install vim-enhanced
sudo dnf install vim-X11        # GUI version

# macOS
brew install vim                # MacVim available separately
# or use pre-installed /usr/bin/vim (limited features)

# Windows
# Download installer from: https://github.com/vim/vim-win32-installer/releases
choco install vim               # Chocolatey
scoop install vim               # Scoop

Method B: Build from Source

# Clone repository
git clone https://github.com/vim/vim.git
cd vim

# Configure (Unix/Linux/macOS)
cd src
./configure --with-features=huge \
            --enable-multibyte \
            --enable-rubyinterp=yes \
            --enable-python3interp=yes \
            --with-python3-config-dir=$(python3-config --configdir) \
            --enable-perlinterp=yes \
            --enable-luainterp=yes \
            --enable-gui=gtk3 \
            --enable-cscope \
            --prefix=/usr/local

# Build
make -j$(nproc)

# Install
sudo make install

Platform-Specific Notes:

  • Windows: See src/INSTALLpc.txt or use src/Make_mvc.mak with Visual Studio
  • macOS: Use src/Makefile with Xcode Command Line Tools
  • Haiku: See READMEdir/README_haiku.txt
  • VMS: See READMEdir/README_vms.txt

3. Configuration

Environment Variables

# Set runtime path (if not using default)
export VIMRUNTIME=/usr/local/share/vim/vim91

# Specify vimrc location
export VIMINIT='source /path/to/your/vimrc'

# Disable vimrc for clean debugging
alias vimclean='vim -u NONE -U NONE -N'

Configuration Files

FileLocationPurpose
vimrc~/.vimrc or ~/.vim/vimrcUser startup settings
gvimrc~/.gvimrcGUI-specific settings
exrc~/.exrcVi compatibility
System vimrc/etc/vimrc or /usr/local/etc/vimrcSystem-wide defaults

Feature Sets (Compile-Time)

Configure with --with-features=:

  • tiny - Minimal POSIX vi compatibility
  • small - Basic editing
  • normal - Default feature set
  • big - Most features
  • huge - All features (recommended)

Runtime Directory Structure

~/.vim/
├── autoload/      # Automatically loaded scripts
├── colors/        # Color schemes
├── compiler/      # Compiler definitions
├── doc/           # Local documentation
├── ftdetect/      # File type detection
├── ftplugin/      # File type plugins
├── indent/        # Indent scripts
├── keymap/        # Key mappings
├── plugin/        # Global plugins
├── syntax/        # Syntax highlighting
└── vimrc          # Optional: keep here instead of $HOME

4. Build & Run

Development Build (Local Testing)

cd src
# Quick build without install for testing
make -j$(nproc)

# Run from build directory without installing
./vim --version
./vim -u NONE -N   # Start without vimrc

Testing

# Run the test suite (requires built binary)
cd src
make test

# Specific test
make test_textformat

Running Modes

# Normal editing
vim filename

# Read-only mode
vim -R filename

# Diff mode
vim -d file1 file2
vimdiff file1 file2

# Binary mode
vim -b binaryfile

# Recovery mode (after crash)
vim -r filename

GUI (Gvim) Build

# Unix/Linux with GTK3
./configure --enable-gui=gtk3 --with-features=huge
make
sudo make install

# macOS (MacVim - separate project)
# Or use: ./configure --enable-gui=carbon (legacy)

# Windows
# Use MSVC nmake with Make_mvc.mak
nmake -f Make_mvc.mak GUI=yes FEATURES=HUGE

5. Deployment

Distributing Custom Builds

# Create portable installation directory
./configure --prefix=/opt/custom-vim --with-features=huge
make
make DESTDIR=/tmp/vim-package install

# Package for distribution
cd /tmp/vim-package
tar czf vim-custom.tar.gz opt/custom-vim

Container Deployment (Docker)

FROM ubuntu:22.04
RUN apt-get update && apt-get install -y vim-nox
COPY vimrc /root/.vimrc
ENV VIMINIT="source /root/.vimrc"
ENTRYPOINT ["vim"]

Configuration Deployment (Dotfiles)

# Initialize vim directory as git repository
cd ~/.vim
git init
git add .
git commit -m "Initial vim config"

# Deploy to new machine
git clone https://github.com/username/vim-config ~/.vim
ln -s ~/.vim/vimrc ~/.vimrc
# Run :PlugInstall or equivalent plugin manager command

System-Wide Deployment

# Install for all users (requires root)
sudo make install

# Custom system location
./configure --prefix=/usr/local --with-vim-name=vim-custom
sudo make install

CI/CD Integration

# GitHub Actions example
- name: Install Vim
  run: |
    sudo apt-get update
    sudo apt-get install -y vim
    
- name: Test vimrc
  run: |
    vim -u vimrc -c 'q' --not-a-term
    vim -u vimrc -c 'Vader! test/*.vader'  # If using Vader testing

6. Troubleshooting

Build Issues

Error: no terminal library found

# Debian/Ubuntu
sudo apt-get install libncurses5-dev

# RHEL/CentOS/Fedora
sudo dnf install ncurses-devel

# macOS
xcode-select --install

Error: cannot find Python3 config directory

# Find correct path
python3 -m sysconfig --configdir
# Use in configure:
./configure --with-python3-config-dir=$(python3 -m sysconfig --configdir)

Error: undefined reference to pthread_create

# Add to configure or Makefile
LDFLAGS="-lpthread" ./configure [options]

Runtime Issues

Colors not displaying correctly

" In vimrc
set termguicolors
set t_Co=256

Or ensure TERM environment variable is set correctly:

export TERM=xterm-256color

Plugins not loading

# Check runtimepath
vim -c 'echo &rtp' -c 'q'

# Verify filetype detection
vim -c 'filetype detect' -c 'set ft?' filename

Slow startup

# Profile startup time
vim --startuptime startup.log file.txt
# Check for slow shell commands in vimrc

Recovery

# List swap files
vim -r

# Recover specific file
vim -r filename.txt

# Delete swap file after recovery
rm .filename.txt.swp

Platform-Specific

Windows: If vim.exe can't find runtime files, set:

set VIM=C:\Program Files\Vim\vim91
set VIMRUNTIME=%VIM%

macOS: System Vim vs Homebrew Vim

# Check which vim
which -a vim
# Use full path to homebrew version
/usr/local/bin/vim --version

Debugging

# Check compiled features
vim --version | grep +

# Verbose mode (9 is highest)
vim -V9logfile.txt filename

# Safe mode (no plugins, no vimrc)
vim --clean filename