Changing the default text editor to vi on Ubuntu is fairly easy however it may be tricky depending on how it has been set since there are numerous ways. In BackTrack Linux for instance the default editor is set using select-editor so if you follow another Ubuntu Linux howto it may tell you to modify the default editor using update-alternatives. Below I describe setting the default text editor using both of the mentioned methods and note a couple other locations where it can be set.
Update Default Text Editor In BackTrack Linux:
To update the default text editor to vi in BackTrack Linux run the below command and select option 3.
- root@bt:~# /usr/bin/select-editor
- Select an editor. To change later, run 'select-editor'.
- 1. /bin/ed
- 2. /bin/nano <---- easiest
- 3. /usr/bin/vim.basic
- 4. /usr/bin/vim.tiny
- Choose 1-4 [2]: 3
- root@bt:~#
You will notice that the select-editor command adds a file to the home directory that specifies the editor called .selected_editor so for the root user the file would be /root/.selected_editor. This file would have the contents below once vi has been selected.
- root@bt:~# cat /root/.selected_editor
- # Generated by /usr/bin/select-editor
- SELECTED_EDITOR="/usr/bin/vim.basic"
- root@bt:~#
So unless you have previously modified the default editor elsewhere you should be good to go on BackTrack Linux. The other command on Ubuntu where you can set the default editor is the update-alternatives command which is explained below.
Modify Ubuntu Text Editor Using update-alternatives:
- root@bt:~# update-alternatives --config editor
- There are 4 choices for the alternative editor (providing /usr/bin/editor).
- Selection Path Priority Status
- ------------------------------------------------------------
- 0 /bin/nano 40 auto mode
- 1 /bin/ed -100 manual mode
- 2 /bin/nano 40 manual mode
- * 3 /usr/bin/vim.basic 30 manual mode
- 4 /usr/bin/vim.tiny 10 manual mode
- Press enter to keep the current choice[*], or type selection number: 3
- root@bt:~#
So again depending on if the default text editor has been set before you likely won’t need the command above. Last but not least the default editor could be set in a users .profile file, .bashrc, or any other file in their home directory that is processed when the user logs in. If you have used both commands above and the default editor is still showing as nano or something else that you did not set then check out files in the users home directory such as .profile. When viewing those files you want to look for lines similar to the below that set the EDITOR environment variable.
Way To Set Default Editor In .profile Or .bashrc:
- EDITOR=vi
- export EDITOR
Basically the above two lines set the EDITOR environment variable and then export it to be used during a shell session such as when you login to a server via SSH.