35

Guys, anyone know how to change linux console editor from vi into vim everytime we execute vi? I'm using Ubuntu and Fedora Core

Funky81
  • 563

9 Answers9

38

First, make sure you have the proper Vim packages installed. The default on many systems is to install a minimal Vim package that is closer to Vi in functionality.

On Red Hat based systems (RHEL, CentOS, Fedora), you need the vim-enhanced package, for example from a CentOS system I have installed:

vim-common-7.0.109-4.el5_2.4z
vim-enhanced-7.0.109-4.el5_2.4z
vim-minimal-7.0.109-4.el5_2.4z

'common' contains common libraries used by all the Vim packages. 'minimal' is the plain vi editor executables as installed by default.

On Debian based systems (like Ubuntu), you need 'vim'. For example:

ii  vim                  2:7.2.079-1ubuntu5  Vi IMproved - enhanced vi editor
ii  vim-common           2:7.2.079-1ubuntu5  Vi IMproved - Common files
ii  vim-runtime          2:7.2.079-1ubuntu5  Vi IMproved - Runtime files
ii  vim-tiny             2:7.2.079-1ubuntu5  Vi IMproved - enhanced vi editor - compact version

These should be installed by default. On Debian/Ubuntu, you can update the default system editor for all users:

sudo update-alternatives --config vi

Select the version you want from the selection menu. Post installation scripts for the vim package should have already updated this, though. Use --config editor to change the default editor for all users on the system (Ubuntu 9.04 original default is nano, for example).

Finally, on a per user basis for any distribution, set up an alias in the user profile. For example if the shell is bash, edit ~username/.bashrc:

alias vi="vim"

Also, you may check the system vimrc (/etc/vimrc, usually) to see if compatibility mode is turned on.

set cp
set compatibility

Will tell Vim to behave more like old-school Vi, no matter how you've handled using Vim per above. Change to 'nocp' or 'nocompatibility' to make Vim more useful.

jtimberman
  • 21,887
29

In your .bashrc:

alias vi=vim
Al.
  • 2,668
12

If you need the changes only for your id, and within a terminal session: alias vi to vim as suggested by AI.

If you want a system-wide change on your machine, soft-link to vim in /usr/local/bin:

sudo ln -s `which vim` /usr/local/bin/vi

Note: Programs can ignore any aliases on vi by running command vi or \vi instead of just vi.

11

If it is a Debian or Ubuntu system, and you want to make this change system wide, you should use update-alternatives (specify with the --config editor options, and you should be golden)

mwalling
  • 487
3

Some dists use vim:s old school mode where it behaves like vi.

check if your .vimrc contains

set nocompatible

I have been fooled by this a couple of times....

Johan
  • 5,515
3

On Debian systems, when you execute the default vim-tiny as 'vi', a different RC file is used - /etc/vim/vimrc.tiny.

To make 'vi' act more like 'vim', edit /etc/vim/vimrc.tiny and change the line:

set compatible

to read:

set nocompatible
0

I did it like that in .profile on using :

    if [ -f "/usr/bin/vim" ]; then  
     alias vi="vim"
    else
     alias vim="vi"
    fi
export EDITOR=vim

So, always is there be it properly or as .

Rohit Gupta
  • 5,096
0

If you use fish, put the below line in ~/.config/fish/config.fish:

alias vi="vim"
0

on Centos 7 this did the trick

sudo update-alternatives --config vi

then

export EDITOR='vim'
export VISUAL='vim'
Nassim
  • 101