RANDOM BITS

A random site by a random clueless human
Random bits of programming, math, and thoughts By a clueless human          Random bits of programming, math, and thoughts By a clueless human

view is just vim in disguise

January 23, 2025

micro   unix   utilities   vim

I recently found out accidentally at work that vim and view were the same thing when I happened to be editing a file on view instead of my beloved vim editor. This should not come to any surprise, plenty of documentation will state this such as the man pages:

$ man -Leng view
VIM(1)                                                                  General Commands Manual                                                                  VIM(1)

NAME
       vim - Vi IMproved, a programmer's text editor

SYNOPSIS
       vim [options] [file ..]
       vim [options] -
       vim [options] -t tag
       vim [options] -q [errorfile]

       ex gex
       view
       gvim gview vimx evim eview
       rvim rview rgvim rgview

Interestingly, the man pages for view points to vim and we can see all sorts of different types of editors listed along with it such as gvim. If we take a look at AIX 7.3 documentation:

Starts the vi editor in read-only mode.

Taking a look at my local system (Fedora 41), we indeed see that is the case:

#!/usr/bin/sh

# run vim -R if available
if test -f /usr/bin/vim
then
  exec /usr/bin/vim -R "$@"
fi

# run vi otherwise
exec /usr/libexec/vi -R "$@"

However, here’s where things gets weird. At work, view was a pointer to vi:

$ realpath view
/usr/bin/vi

However, on my other development machine, view was simply another binary that had the same md5sum. This has made me theorized that vi checks its name to see whether or not to open the file in read-only mode based if it started with the name view. So I made an experiment by creating a new “binary” called view-pika (by creating a link to vim). The result was as I theorized: it opened the file as READ-ONLY. I’ll go a deeper dive on my blog sometime this week to understand why (spoiler, it’s essentially what I theorized).