5

When I type vi into a terminal it shows the following display:

vi

Note that it says vim not vi, I'm sure I haven't downloaded vim yet and that this is actually vi not vim: for example the arrow keys print ABCD instead of moving.

6
  • 2
    It easy to check update-alternatives --display vi
    – Costas
    Feb 3, 2015 at 16:19
  • 2
    Or readlink -e $(which vi) for non-debian distros
    – Costas
    Feb 3, 2015 at 16:28
  • Gotta agree w/ Random832 re: the ABCD arrow keys thing is a tangential issue. I've never seen vim behave that way.
    – goldilocks
    Feb 3, 2015 at 16:57
  • 1
    @goldilocks I consistently get this behavior (on certain terminals, anyway) from "tiny/basic" versions of vim and not from the full version on the same systems. I suspect there's some compilation option that's disabled in the tiny versions that makes it work differently.
    – Random832
    Feb 3, 2015 at 17:06
  • 2
    If it quacks like a vim, it is a vim. :-)
    – Jens
    Feb 3, 2015 at 21:55

6 Answers 6

26

While the original vi is still available, I do not think it is much used on current linux or BSD distributions;1 apparently it was dusted off in 2000 after having been mothballed a decade before that, and the last release was 2005.

There are various implementations of vi around, which is really now a POSIX specification. These include nvi and elvis, but the most popular is probably vim.

On systems that use vim, vi will simply be a softlink to it and when invoked this way it should start in vi-compatible mode, so the system has something that conforms to the POSIX spec. However, that doesn't change the actual name of the program, which is vim, and that's what you see on the title screen.


1. Although it is available on Arch, at least. You might find it other places too.

3
  • Arch Linux has this vi by default.
    – Renan
    Feb 3, 2015 at 16:44
  • @Renan So it is; edited.
    – goldilocks
    Feb 3, 2015 at 16:50
  • 1
    @Renan, pedantry: Arch Linux installs no application by default. Vi is part of the "base" group, which most people will select, but the Arch install process does not force you to install it.
    – sleblanc
    Feb 4, 2015 at 15:29
15

If you are using Debian then vi is opening as vim because of the entry of vi in /etc/alternatives. Let me break this up for you.

When you do ls -l /usr/bin/vi:

lrwxrwxrwx 1 root root 20 Jul  1  2014 /usr/bin/vi -> /etc/alternatives/vi

As you can see the vi binary is a symbolic link to /etc/alternatives/vi.

Now if you do ls -l /etc/alternatives/vi:

lrwxrwxrwx 1 root root 18 Jul  1  2014 /etc/alternatives/vi -> /usr/bin/vim.basic

It's a symbolic link to the binary of vim.basic.

So, in a nutshell: /usr/bin/vi/etc/alternatives/vi/usr/bin/vim.basic

As a result if you type vi in the shell, vim.basic will open.

You can check and change the values in the /etc/alternatives by the command update-alternatives but I think your original question is already answered.

8

On many Linux systems, the default vi really is a version of Vim, typically one compiled with fewer options (no built-in perl and python support, no GUI, etc) than the one you would get if you installed a Vim package.

for example the arrow keys print ABCD instead of moving.

This is caused by an inconsistency between your terminal emulator and Vim's understanding of the terminfo/termcap entry being used. Generally, it is caused by Vim having sent the t_ks code to "enable" the arrow keys (actually puts them in a mode where they send <1b>OA instead of <1b>[A) but the expected keys are for the other mode (e.g. t_ku=<1b>[A for up arrow). Try changing your TERM environment variable or vim option (set term=builtin_ansi or builtin_xterm in vimrc might work, though it may disable color), using a different terminal, or as a last resort adding set t_ks= t_ke= to your .vimrc file to disable this mode switching. This is a suggested solution in vim's help files, the next paragraph after :help cs7-problem.

This behavior is not in any way a sign that it is "actually vi not vim" - most modern "genuine" versions of vi or nvi also support the arrow keys.

5

The original question has already been answered explaining that vi is an alias for vim, and that it is normal for the command vi to start vim.

What should be noted is that vim is (in some setups) sensitive to which name it is called by. Even though vi and vim both execute the same binary they can behave differently.

2

Note in several Debian based distros the symbolic link in /bin/vi is to 'busybox' and not vim at all. In some cases this can be OK but the features busybox provides are a minimum set and for some reason seem to vary on how busybox was compiled.

If vim is installed it usually replaces the busybox link -- but sometimes not so -- busybox may still be linked to /bin/vi while vim is linked to /usr/bin/vi -- so it will depends on the PATH environment variable on which is found first. A typical user may get 'vim' but when logged in as 'root' get busybox vi.

Best to check and see which vi link you are using (which vi) and what that is linked to.

1
2

Anyway, vim is a superset of vi. Meaning, everything that works in vi works in vim. For all intents and purposes, it is a more extensible version of vi.

for example the arrow keys print ABCD instead of moving.

There are 2 solutions to this.

  • Change your terminals character encoding to something compatible with vi.
  • Add set nocompatible somewhere in your ~/.vimrc (You can make the file if you don't have it). then restart your termninal.

The second solution has always worked best for me.

3
  • See stackoverflow.com/questions/1159206/difference-between-vi-vim for differences between vi and vim
    – StephenS
    Feb 3, 2015 at 22:22
  • I'm not a big vi fan, but according to this, character encoding and set nocompatible have nothing to do with what the vi command resolves to... Besides, setting nocompatible is said to "stop vim from behaving in a strongly vi-compatible way", which, in a way, is the opposite of what the OP seems to be looking for. Feb 3, 2015 at 22:43
  • 2
    Someone had already helped OP with the original issue of vi linking to vim, so I was addressing different solutions to the 'ABCD' spam. Which is why I immediately preceded the list with the quote stating his ABCD issue. Like I said, this should have been a comment on the original question instead of an answer, but this account currently lacks the reputation to post comments on any thread other than my own.
    – StephenS
    Feb 3, 2015 at 22:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .