10

On Debian-based systems the alternatives system handles both the vi and vim executable. So if vim is installed and you execute vi, you also get vim, which I find very nice, because I absolutely hate classic vi.

On Fedora 17 "Beefy Miracle", the alternatives system obviously doesn't handle none of the two. But there is a profile file in /etc/profile.d/vim.sh which adds a shell alias to make vi execute vim. For some reason it does not do that for system users, including root.

But even if I set up an alias for all users manually, when I call sudo vi I'm starting classic vi instead of vim. That's probably because sudo doesn't start a shell or profile files are only executed in interactive shell sessions.

What I'm looking for now is a way to uninstall classic vi completely to make a symlink that even survives system updates. How can I remove classic vi but not vim on Fedora 17? Or is there even a better way?

Update: With yum provides vi I found out that vi is provided by the package vim-minimal. But I can't simply remove it because it automatically removes the package sudo with it. Even if I do remove it, and try to install sudo again afterwards, vim-minimal is then again installed as dependency.

Update: As requested, output of rpm -qf /usr/bin/vi:

vim-minimal-7.3.444-1.fc17.x86_64 

And ls -l /usr/bin/vi:

-rwxr-xr-x. 1 root root 782248 13. Feb 2012 /usr/bin/vi 
6
  • rm /usr/bin/vi; ln -s /usr/bin/vim /usr/bin/vi. Not an answer because I would personally find a better way (or type vim if I wanted vim). Commented Dec 12, 2012 at 1:47
  • @jordanm I meant exactly this when I asked to make a symlink survive an update. How do you ensure the link doesn't get overwritten when vim-minimal package is updated? Commented Dec 12, 2012 at 2:51
  • Is /usr/bin/vi a symlink (to what) or a regular file on Fedora? If a regular file, from what package? Commented Dec 12, 2012 at 23:10
  • @Gilles I don't understand your question. Commented Dec 12, 2012 at 23:45
  • Post the output of ls -l /usr/bin/vi and rpm -qf /usr/bin/vi. Commented Dec 12, 2012 at 23:46

3 Answers 3

6

Your vi is Vim, but invoked as vi, so it enters historical compatibility mode. The recommended action is that if you want to run Vim and not vi, run vim and not vi. However, if you want vi to always run Vim on every account on the system, override it in /usr/local/bin:

cat >/usr/local/bin/vi <<\EOF #!/bin/sh exec /usr/bin/vim "$@" EOF chmod 755 /usr/local/bin/vi 
6
  • That's actually a very nice idea. Commented Dec 13, 2012 at 2:35
  • 2
    It even works by simply making a symlink with sudo ln -s /usr/bin/vim /usr/local/bin/vi. But you have to add /usr/local/bin to the left-most side of the Defaults secure_path="…" configuration in visudo, else the symlink won't be found. Commented Dec 17, 2012 at 19:33
  • I think there are some typos in the syntax here. Did you mean cat >/usr/local/bin/vi (not cat >/usr/local/bin)? Did you mean chmod 755 /usr/local/bin/vi (not .../vim)? Commented Feb 13, 2013 at 2:57
  • To pick it up with root's default PATH, create the symlink at /usr/local/sbin/vi. Commented Sep 25, 2019 at 16:49
  • It is never a good idea to overwrite a system binary. It is better to create an alias for things like that. Commented May 22, 2021 at 23:06
6

# echo 'alias vi="vim"' >> /etc/bashrc' or # alternatives --install /usr/bin/vi vi /usr/bin/vim 900

2
  • And doesn't that get erased when the vim-minimal package is updated? Commented Dec 12, 2012 at 2:50
  • create an alias on .bashrc is a good pratice...to me @llua gave a good answer Commented Feb 13, 2013 at 11:35
1

FYI recent fedora (at least since 18) installs that alias gobally in /etc/profile.d once vim-enchanced is installed.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.