8.86. Vim-9.1.1202

The Vim package contains a powerful text editor.

Approximate build time: 3.4 SBU
Required disk space: 251 MB
[Tip]

Alternatives to Vim

If you prefer another editor—such as Emacs, Joe, or Nano—please refer to https://www.linuxfromscratch.org/blfs/view/svn/postlfs/editors.html for suggested installation instructions.

8.86.1. Installation of Vim

Create the PKGBUILD for the Vim package with the following commands:

mkdir /sources/vim
cd /sources/vim
cat > PKGBUILD << "REALEOF"
# Maintainer: Linux From Scratch <lfs-dev@lists.linuxfromscratch.org>

pkgname="vim"
pkgver="9.1.1202"
pkgrel="1"
pkgdesc="The Vim package contains a powerful text editor."
arch=('x86'
      'x86_64')
url="https://www.vim.org"
license=('VIM')
groups=('core')
depends=('acl'
         'attr'
         'glibc'
         'python'
         'ncurses'
         'tcl'
         'rootfs')
makedepends=('bash'
             'binutils'
             'coreutils'
             'diffutils'
             'gcc'
             'grep'
             'make'
             'sed')
optdepends=('xorg'
            'gtk+2'
            'lesstif'
            'ruby'
            'gpm')
backup=('etc/vimrc')
source=('https://github.com/vim/vim/archive/v9.1.1202/vim-9.1.1202.tar.gz')
md5sums=('97d30bee45129ac75b95dd0ade5c10e0')

prepare(){
  cd "${pkgname}-${pkgver}"

  # Change the default location of the vimrc configuration file to /etc
  echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
}

build(){
  cd "${pkgname}-${pkgver}"
  ./configure --prefix=/usr
  make
}

check(){
  cd "${pkgname}-${pkgver}"
  # The test suite outputs a lot of binary data to the screen. This can cause
  # issues with the settings of the current terminal (especially while we are
  # overriding the TERM variable to satisfy some assumptions of the test suite).
  # The problem can be avoided by redirecting the output to a log file as shown
  # below. A successful test will result in the words ALL DONE in the log file
  # at completion.
  # The tests are also known to have timing issues if run in parrallel
  LANG=en_US.UTF-8 make -j1 test &> vim-test.log || true
  grep "ALL DONE" vim-test.log > /dev/null 2>&1 || false
}

package(){
  cd "${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install

  # Create a vi compatibility link and man pages
  ln -sv vim "${pkgdir}/usr/bin/vi"
  for L in "${pkgdir}"/usr/share/man/{,*/}man1/vim.1; do
      ln -sv vim.1 $(dirname $L)/vi.1
  done

  # By default, vim installs documentation in /usr/share/vim
  install -vdm755 "${pkgdir}/usr/share/doc"
  ln -sv ../vim/vim82/doc "${pkgdir}/usr/share/doc/${pkgname}-${pkgver}"

  # Create a default vimrc
  # Note: this will be updated manually immediately after the build
  install -vdm755 "${pkgdir}/etc"
  cat > "${pkgdir}/etc/vimrc" << "EOF"
" Begin /etc/vimrc

" Ensure defaults are set before customizing settings, not after
source $VIMRUNTIME/defaults.vim
let skip_defaults_vim=1

set nocompatible
set backspace=2
set mouse=
syntax on
if (&term == "xterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF
}
REALEOF

Prepare the build directory for the pacman user and build the package:

chown -R root:pacman .
chmod 2775 .
chmod 664 PKGBUILD
su pacman -c 'makepkg -L --nodeps'

Add the newly created package to the central package repository:

cp vim-9.1.1202-1-$(uname -m).pkg.tar.xz \
   /srv/pacman/repos/LFS/
repo-add /srv/pacman/repos/LFS/LFS.db.tar.xz \
         /srv/pacman/repos/LFS/vim-9.1.1202-1-$(uname -m).pkg.tar.xz

Update the local cache and install the Vim package:

pacman -Syu
pacman -S vim --overwrite \* -dd --noconfirm

Finally, copy the source files into the source repository and clean up the build directory:

mkdir /srv/pacman/source/LFS/vim
cp PKGBUILD /srv/pacman/source/LFS/vim
cd /sources
rm -rf vim

If an X Window System is going to be installed on the LFS system, it may be necessary to recompile Vim after installing X. Vim comes with a GUI version of the editor that requires X and some additional libraries to be installed. For more information on this process, refer to the Vim documentation and the Vim installation page in the BLFS book at https://www.linuxfromscratch.org/blfs/view/svn/postlfs/vim.html.

8.86.2. Configuring Vim

The minimal /etc/vimrc installed above introduces only a handful of configuration settings:

The set nocompatible setting makes vim behave in a more useful way (the default) than the vi-compatible manner. Remove the no to keep the old vi behavior. The set backspace=2 setting allows backspacing over line breaks, autoindents, and the start of an insert. The syntax on parameter enables vim's syntax highlighting. The set mouse= setting enables proper pasting of text with the mouse when working in chroot or over a remote connection. Finally, the if statement with the set background=dark setting corrects vim's guess about the background color of some terminal emulators. This gives the highlighting a better color scheme for use on the black background of these programs.

Documentation for other available options can be obtained by running the following command:

vim -c ':options'
[Note]

Note

By default, vim only installs spell-checking files for the English language. To install spell-checking files for your preferred language, copy the .spl and optionally, the .sug files for your language and character encoding from runtime/spell into /usr/share/vim/vim91/spell/.

To use these spell-checking files, some configuration in /etc/vimrc is needed, e.g.:

set spelllang=en,ru
set spell

For more information, see runtime/spell/README.txt.

8.86.3. Contents of Vim

Installed programs: ex (link to vim), rview (link to vim), rvim (link to vim), vi (link to vim), view (link to vim), vim, vimdiff (link to vim), vimtutor, and xxd
Installed directory: /usr/share/vim

Short Descriptions

ex

Starts vim in ex mode

rview

Is a restricted version of view; no shell commands can be started and view cannot be suspended

rvim

Is a restricted version of vim; no shell commands can be started and vim cannot be suspended

vi

Link to vim

view

Starts vim in read-only mode

vim

Is the editor

vimdiff

Edits two or three versions of a file with vim and shows differences

vimtutor

Teaches the basic keys and commands of vim

xxd

Creates a hex dump of the given file; it can also perform the inverse operation, so it can be used for binary patching