Index ¦ Archives ¦ Atom ¦ RSS

vi

Understanding vi and vim on Debian

Since 2011, I have steadfastly embraced vi as my primary text editor. My journey into mastering the command-line interface and transitioning away from the comfort of the graphical user interface began early. Among the foundational skills I sought to acquire, efficient text file editing was one of the first.

Surprisingly, the exact catalyst that led me to embrace vi has faded into the distant recesses of my memory. Nevertheless, over eleven years later, my loyalty to vi remains unwavering. It has been a constant companion throughout my journey, and I have never strayed into the world of alternative text editors. I have even used vi for basic Python programming tasks, underscoring its versatility and enduring utility in my daily computing endeavors.

In this post, I will delve into the intricacies of how Debian manages the functionality of vi and vim in a basic, uncustomized Debian installation.

My objective is to gain a profound understanding of the default behavior of vi and vim in their most minimalist configurations, as presented immediately after a fresh Debian installation.

It's worth noting that Debian does not include vim by default in this setup. I opted for a network installation using the minimal tasksel profile, selecting only the mate-desktop-environment package. This highlights one of the aspects I greatly appreciate about Debian—its commitment to providing essential software components while allowing users to shape and personalize their tools and environments without presumption.

vi

A pristine Debian installation includes only the vim-tiny package. Within this package, two critical configuration files are stored in /etc/vim/: vimrc and vimrc.tiny.

This setup is intentionally minimalist, devoid of any symbolic links, aliases, or binary files associated with vim. The only alias present is vi, which is linked to vim.tiny.

When vi is invoked, it calls vim.tiny, which, by default, sources the file located at /etc/vim/vimrc.tiny.

Now, let's explore the contents of the /etc/vim/vimrc.tiny file:

" Vim configuration file in effect when invoked as 'vi'. This configuration
" aims to provide a Vim environment as compatible with the original 'vi' as possible.
" Note that ~/.vimrc and other runtimepath configuration files are still sourced.
" When Vim is invoked as 'vim', 'view', 'evim', etc., this file is _not_ sourced.
" In such cases, /etc/vim/vimrc and/or /etc/vim/gvimrc are used.

set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
set compatible
" vim: set ft=vim:

This configuration ensures that vi (invoking vim.tiny) mimics the original vi. It also loads configuration files from the $VIMRUNTIME directory, including ~/.vimrc and other runtimepath files. Specifically, it prioritizes:

  • /usr/share/vim/vim82/debian.vim
  • /usr/share/vim/vim82/defaults.vim

Finally, the set compatible directive ensures compatibility with the original vi, even if other configurations attempt to disable it.

By default, vi links to vim.tiny:

pionen@lilit:~$ ls -la /etc/alternatives/vi
lrwxrwxrwx 1 root root 16 Oct 12  2022 /etc/alternatives/vi -> /usr/bin/vim.tiny

If vim is explicitly installed, additional aliases (e.g., view or evim) and configuration files, such as /etc/vim/vimrc and /etc/gvimrc, become active. These configurations enable enhanced features:

runtime! debian.vim
" Uncomment below to make Vim more Vi-compatible.
" set compatible
" Syntax highlighting example:
" syntax on

" Enable additional plugins or rules:
" filetype plugin indent on

" Uncomment to remember the last position in a file:
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

When using vim, you can check the runtime path and sourced scripts:

:echo $VIMRUNTIME
/usr/share/vim/vim82
:scriptnames
1: /usr/share/vim/vimrc
2: /usr/share/vim/vim82/debian.vim
3: ~/.vimrc

This confirms that user-defined configurations in ~/.vimrc override defaults. Any required settings from /usr/share/vim/vim82/defaults.vim should be manually incorporated into ~/.vimrc if needed.

In the next post, I will explain my choice of vim versions available in the Debian repository and the rationale behind my selection.

© Porfirio Páiz. Built using Pelican. Theme by Giulio Fidente on github.