Software & AppsOperating SystemLinux

How To Change Default Crontab Editor to Vim on Ubuntu

Ubuntu 14

In this guide, we are going to discuss how to change the default crontab editor to Vim on Ubuntu. The default editor for crontab in Ubuntu is usually nano. However, if you are more comfortable using vim, you can set it as the default editor for crontab.

Quick Answer

To change the default crontab editor to Vim on Ubuntu, you can use the update-alternatives command. First, check the current default editor using sudo update-alternatives --display editor. Then, configure the default editor using sudo update-alternatives --config editor and select Vim as the default editor. Verify the change using update-alternatives --display editor and restart your SSH session.

What is Crontab?

Crontab (short for Cron Table) is a file which contains the schedule of cron entries to be run and at specified times. It is used to schedule tasks to run on specific time.

What is Vim?

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.

Steps to Change Default Crontab Editor to Vim

1. Check the Current Default Editor

First, let’s check the current default editor. You can do this by typing the following command in your terminal:

sudo update-alternatives --display editor

This command will display the current default editor along with other available editors.

2. Configure the Default Editor

To change the default editor, you can use the update-alternatives command followed by --config editor. This command is used to maintain symbolic links determining default commands.

sudo update-alternatives --config editor

This command will display a list of available editors and their priorities. You will be prompted to select the editor you want to use by default.

3. Select Vim as the Default Editor

In the list of editors displayed, each editor has a corresponding number. Enter the number for /usr/bin/vim.basic and press Enter. This will set vim as the default editor.

4. Verify the Change

To confirm that the default editor has been changed to vim, you can run the update-alternatives --display editor command again. It should now show vim as the default editor.

5. Change Default Editor for Individual Users

If you have multiple users and want to change the default editor for each user, you can run the update-alternatives --config editor command without sudo. This will configure the default editor for the current user.

6. Restart Your SSH Session

Finally, restart your SSH session or SSH daemon for the changes to take effect.

Conclusion

After following these steps, the crontab -e command should open the crontab file in vim instead of nano. If the changes don’t take effect, make sure that the EDITOR and VISUAL environment variables are not set to nano. You can check and modify these variables by running echo $EDITOR and echo $VISUAL. If they are set to nano, you can change them to vim by running export EDITOR=vim and export VISUAL=vim.

Changing the default editor to vim can make editing crontab files easier and more efficient, especially if you’re already familiar with vim. However, if you’re new to vim, you might want to spend some time learning its commands and features. You can do this by running vimtutor in your terminal.

We hope this guide was helpful. If you have any questions, feel free to ask in the comments section below.

Ask Ubuntu post has more information and alternative solutions.

How can I check the current default editor for crontab in Ubuntu?

You can check the current default editor for crontab in Ubuntu by running the command sudo update-alternatives --display editor in the terminal.

How do I change the default crontab editor to Vim?

To change the default crontab editor to Vim, you can use the command sudo update-alternatives --config editor. This will allow you to select Vim as the default editor from the available options.

Can I change the default editor for individual users?

Yes, you can change the default editor for individual users by running the update-alternatives --config editor command without sudo. This will configure the default editor for the current user.

How can I verify if the default editor has been successfully changed to Vim?

To verify if the default editor has been changed to Vim, you can run the command update-alternatives --display editor again. It should now display Vim as the default editor.

Do I need to restart my SSH session after changing the default editor?

Yes, it is recommended to restart your SSH session or SSH daemon for the changes to take effect.

What should I do if the changes don’t take effect after following the steps?

If the changes don’t take effect, make sure that the EDITOR and VISUAL environment variables are not set to nano. You can check and modify these variables by running echo $EDITOR and echo $VISUAL. If they are set to nano, you can change them to vim by running export EDITOR=vim and export VISUAL=vim.

Leave a Comment

Your email address will not be published. Required fields are marked *