0

My first post on unix.stackexchange.com. Please, don't just react by the title of this post as I'm not jumping in having not researched what I'm asking for.

I have done quite a research about Vi vs. Vim topic. As several forums, and as also this, this or this threads speak, Vim is a superset of Vi, adding quite a lot of useful perks on top.

Confusion #1
However, right now, I'm doing a bit of in-depth Linux course (want to learn this OS better), and The Linux Foundation instructor says, that:

usually, installed program on the distribution is Vim, and Vi just links to it as an alias.

This seems plausible, as disregarding of whether I open vi or vim from my terminal, absolutely identical welcome screen launches, with identical software name, version, author and etc..

Confusion #2
However, which vim and which vi print different files from /usr/bin/ directory.

So, I'm really confused, because on one hand a lot of people speak that Vim is a superset of Vi, but on the other hand, the course I'm doing now says, that it's both Vim, and opening vi or vim, actually, almost(as they show up as identical software but behave differently) proves it.

Confusion #3
So,

  1. Why people say, that Vi and Vim are two different programs and that Vim is a superset of Vi? as they even have identical welcome screen and version numbers, at least, on CentOS 7;

  2. or maybe Vi is an alias of Vim specifically on CentOS 7 (which I'm using now) and usually (on other OSes) they are two different programs? but then again, they are two different binaries.. but they have absolutely identical welcome screen, which is really confusing;

  3. If they are not different, why opening my .java source file is highlighted when I open it with vim and - is not, when I open it with vi?

I'm sorry if this text is a bit mashed up, but that is exactly what confuses me, as well, and what is the whole information I have gathered and observed.

They seem to be same (also are claimed by the instructor), but they are told to be different (on different forums) and they actually behave (this java file case) and show up (with which) as different.

So, what shall I understand from this?

Update:

As asked to do, vi --version and vim --version output this:

vi --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 15 2020 16:43:23)
Included patches: 1-207, 209-629
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):

vim --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 15 2020 16:44:08)
Included patches: 1-207, 209-629
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):
11
  • 1
    rpm -qf /usr/bin/vi => vim-minimal-7.4.629-8.el7_9.x86_64; and rpm -qf /usr/bin/vim => vim-enhanced-7.4.629-8.el7_9.x86_64. -q is for query, and -f for Query package owning FILE, in RHEL family. So, does this mean that they are different programs but very similar? is my guess correct? how come that even versioning numbers, release dates, and everything else match then?.. Jan 3 at 1:54
  • 2
    vim-minimal is a stripped down version (more like vi) without syntax-highlighting, compare the feature lists of vi --version and vim --version.
    – Freddy
    Jan 3 at 3:57
  • 1
    Also, I really would appreciate the reason of downvoting.. I'm not hunting for votes.. but I also don't think, that this questions deserved a downvote. I really have approached and researched this from different angles. Jan 3 at 12:17
  • 1
    @AdminBee I think I know how the StackExchange sites work, in general, and this is not my first question. It's just first on unix site, but general rules of thumb apply everywhere. I don't agree that my question contains several problems - it clearly states that the only problem here is vi vs. vim; however, another story is where and in what circumstances I find these two to be counterintuitive, which I explain as thoroughly as I can. Thank you for your points, but I don't think I agree with them, and my question doesn't violate "one question per post". Your second point is unclear. Jan 4 at 21:54
  • 1
    I think your question is pretty appropriate for Unix & Linux, since there are many points on the versions shipped by CentOS, the two RPM packages and so on... If you have more questions on Vim (or Vi, or the history of them), there's also a Vi and Vim stack for you, you'll be very welcome there!
    – filbranden
    Jan 6 at 15:00
2

Vim is indeed derived from Bill Joy's original vi. However, nowadays because development on vim is significantly greater than vi, many distros (including CentOS) emulate the original vi behaviour using vim compiled with fewer features.

To answer your questions/confusions:

  1. When you open vi, it opens the same start screen as vim (which describes itself as vim) because it is in fact a stripped-down vim that you are running, not the original vi.

  2. /usr/bin/vi and /usr/bin/vim are different binaries because they are both actually compiled from vim's source code but with different features (options).

  3. Syntax highlighting is not available when you use vi file.java but is for vim file.java because of the different options they have been compiled with. If you look closely at the output of /usr/bin/vim --version and /usr/bin/vi --version you will see that the former show +syntax, amongst other features, whereas the latter has -syntax. That list is what I am referring to regarding "features it has been compiled with".

I hope that helps, and can see why it might be confusing.

1
  • Thank you Andrew. Just don't wanna copy-paste the same comments, and please have a look at our discussion in another answer's comments. P. S. --version don't output different strings.. see the update in the question. They never mention anything like +syntax. Jan 3 at 15:16
2

The original vi was created by Bill Joy in 1976. The vi editor has since been re-implemented several times, and the name vi is now used in the sense "any program that roughly implements the commands and keybindings of the original vi." You could say that vi has lost its trademark, just like the words "Aspirin" and "Escalator."

Vim is said to be superset of vi because it implements a lot more features than the original vi, but still roughly remains compatible with "vi".

The reason both the commands vi and vim exist on your machine is that there are some (perceived) uses for a program that behaves exactly like "vi". The vi program is smaller, so it starts up faster. Vim might do some editing commands a bit differently, which may be considered wrong. This is especially important when vi commands are scripted, and the output is required to be "just right" if it is consumed by some other program or script.

The same design has been applied with the Bash shell, which is two programs in one. When invoked as sh, Bash mimics the original /bin/sh, i.e. it restricts its features and in some ways behaves a bit differently than when invoked as bash.

The reason you see the same welcome screen and matching version numbers is that both programs come from the same source, and are developed in tandem. They probably even share the same source code.

9
  • So, they are different software programs, but they have identical version strings, identical build numbers, identical names.. and everything copycatted? well, a super bad manner and style to release the software then. One is not born with all this knowledge and it's 100% confusing if you just happen to want to learn about them. How this non-descriptive-at-all two executables should be differentiated.. strange.. and now this is a discouraging point for me in Linux.. although I really like a lot of things in this OS. Jan 3 at 12:06
  • @GiorgiTsiklauri They are one and the same program, from GitHub, but in your system vi is the executable built with less features and vim with more features. The original Vi can still be found at ex-vi.sourceforge.net, but no mainline distro seems to be willing to use it as long as there is Vim around.
    – Quasímodo
    Jan 3 at 12:29
  • @GiorgiTsiklauri Vi is a editor mandated by POSIX, the Portable Operating System Interface family of standards, which Linux distributions try to adhere to. POSIX also says the name of the editor is vi. Other standard utility programs originated from Unix and specified by POSIX are sh, ls, cp, mv, rm, cat, sed, awk, wc, grep, and so on. None of these programs in a modern Linux distribution have any source code common with the original Unix versions of the programs, they are all "copycatted". Jan 3 at 14:12
  • @JohanMyréen thank you, but I don't wanna lie and show up as it's crystal-clear now. I understand, that there is a history, an inheritance and etc. also, I understand, that lots of utility programs are originated from old Unix. Still.. my questions seem to me crystal-clearly simple: 1) are these two (vi/vim) same? seems like not, at least on CentOS; 2) why the Linux Foundation (should be best) instructors say, vi is usually symlink to vim? not on CentOS, as I can see; 3) Different builds, with different options, are different software programs, even if they come from same source. Jan 3 at 15:12
  • So, why they just mirror each other bit by bit, in build versions and every other metainformation? don't you agree that this is extremely misleading and wrong? it's like they clearly are different (doesn't matter that source is same.. final builds differ), but they don't even mention this in the metainformation/description. This is not cool.. at all.. imagine a person who is aspiring to learn Linux.. how should one get this clear in their brain? I'm not a "ok, doesn't matter" person.. and I try to pay attention to every single bit of information.. and vi and vim are so popular.. pity. Jan 3 at 15:14
1

From your vi --version and vim --version outputs:

vi --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 15 2020 16:43:23)
Included patches: 1-207, 209-629
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):


vim --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 15 2020 16:44:08)
Included patches: 1-207, 209-629
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):

... I would conclude the following:

At Dec 15 2020, 16:43:23 of whatever timezone RedHat's package builder was using, it unpacked the vim 7.4 source code, applied a large number of patches to it, and then set out to build a binary with a set of compile-time configuration settings that was designed to be as compact as possible and maximally compatible with the classic vi, even if that meant disabling user-friendliness features. The resulting binary was to be named /usr/bin/vi. This would be packaged as the RPM package vim-minimal.

Note: although the resulting binary is named vi, this is still unquestionably Vim - just in vi compatibility mode by default.

Then, at 16:44:08, another package build job started with the same source code and patches, but with different compile-time configuration settings. This job was configured to build a more modern, more featureful configuration, even though it would consume somewhat more disk space and might be very slightly different from the classic vi in some respects. The binary resulting from this compilation would be named /usr/bin/vim and packaged as vim-enhanced.

(Since this version says Small version without GUI, it is not the version packaged as vim-X11 - that would be a third build run and a yet another RPM package.)


The original vi was written by Bill Joy in the 1970s, released as part of BSD Unix in 1978, and since then licensed to various commercial Unixes. In 1983, the ownership of the codebase was adopted by AT&T as part of their UNIX System V. As a result, until the licensing rules were relaxed in 2002, only people and companies with an AT&T source license could distribute vi. And so, people looking for a free Unix-style editor started to write clones of the original vi, in order to have a version that would work the same but was free of the costly license requirement.

vim was one of these clones, with enhancements. It was released to the public in 1991 and since then been subject for much cross-platform development. This made it more featureful than the original vi, and it's probably currently the most widespread of the clones of vi.

RedHat's packaging of Vim splits the binaries generated from single source code package into several RPM binary packages: vim-common, vim-filesystem, vim-minimal, vim-enhanced and vim-X11. Of these, vim-filesystem defines some directories where other packages may drop in syntax or filetype definitions or other files that add functionality to Vim. vim-common depends on the vim-filesystempackage and contains files required by vim-enhanced or vim-X11. The online help files within vim-common are also usable by vim-minimal but not strictly required.

The vim-minimal provides [/usr]/bin/vi, and also binaries /usr/bin/ex, /usr/bin/rvi, /usr/bin/[r]view, configuration file /etc/virc and their man pages.

vim-enhanced provides /usr/bin/vim with more modern compile-time configuration defaults, but still with terminal-based UI only. It explicitly requires Perl and vim-common. vim-X11 provides a version of Vim with full X11 GUI and mouse support (with a binary named /usr/bin/gvim), and has the same requirements as vim-enhanced plus a set of X11 icons and libraries.

Even if you select "minimal installation" in the RedHat installer, it will probably include vim-minimal. But the vim-enhanced or vim-X11 will be completely optional.

If you want to understand the process at a deeper level, I would urge you to download the corresponding .src.rpm package from which all these binary RPMs are built, extract it into an empty directory, and study the vim.spec file at the root directory. That file includes the exact configuration options for each version of Vim.

If you are interested in the traditional vi, you can find it at ex-vi.sourceforge.net. But most modern Linux distributions (that are not aiming for embedded platforms or otherwise restricting themselves for absolute minimum size) are likely to use Vim as a replacement of traditional vi.

1
  • @tecoM thank you very much for your contribution. I'll have some time to parse everything you wrote step by step, and I'll get back with my comment. I just happen not to be actively surfing the web these days.. which might be the reason of a bit delayed reply. Jan 4 at 21:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.