One of the most common activities when managing cron jobs is editing the crontab file. By default, the system specifies the editor for you. But, what if you’d rather use your favourite text editor such as Nano or Vim? In this article, we’ll show you how to specify either Nano or Vim as your crontab editor.
What You Need to Know
This process involves setting an environment variable called VISUAL. It is a standard Unix environment variable that determines which editor is invoked when a program wants to start a text editor. Here, we’ll set it to either Nano or Vim before running the
crontab -e command.
It’s important to note that in order to use Nano or Vim, they must be installed on your system. Most Unix-like systems come with both pre-installed.
Setting Nano as the Crontab Editor
To specify Nano as the crontab editor, you will need to run the following command:
export VISUAL=nano; crontab -e
After running this command, Nano will be used as the text editor for your current crontab session.
Setting Vim as the Crontab Editor
If you’d rather use Vim, the process is quite similar. Run the following command:
export VISUAL=vim; crontab -e
Once this command is run, Vim will be used as the text editor for your current crontab session.
Making Vim or Nano the Permanent Crontab Editor
If you’d like to make Vim or Nano your default crontab editor across all sessions, you can add the export line to your shell profile file.
For bash users, add the following line to your
echo 'export VISUAL=nano' >> ~/.bashrc
echo 'export VISUAL=vim' >> ~/.bashrc
Then, source the file to apply the changes:
Now, every time you invoke
crontab -e, it will automatically open in the specified editor.
We hope you found this article helpful. If you did, please feel free to share it with others who might also benefit. If you have any questions or need further clarification, don’t hesitate to get in touch.