How to save and exit crontab -e?

i tried every method listed here and none works, i have a centos 5, vi comes by default with yum and i installed nano


just changed the default editor

export EDITOR=nano

and now i can do what I do using nano :) thanks everyone and yes i should learn Vi.. someday!!!

  • echo $EDITOR? – quanta Sep 4 '11 at 16:25
  • @quanta sir didn't work well maybe I'm doing something wrong since I'm used to use nano and not vi ok so I open contab -e, write echo $EDITOR and press enter, it does not exit, it goes down 1 line – user Sep 4 '11 at 16:38
  • No, I mean type echo $EDITOR from the terminal to determine what default editor you are using. – quanta Sep 4 '11 at 16:49
  • @quanta thank you for reminding me that i can change my default editor :D – user Sep 4 '11 at 17:14
  • for users coming here; apparently the default editor is decided in /usr/bin/sensible-editor and on my installation it decided on the editor called 'ed' as default. Ed can be exited by typing 'q' followed by 'Enter'. – immeëmosol Oct 27 '16 at 13:43

As others have pointed out, the first thing is to make sure you're using an editor you like.

We're all admins here, so we all like vi (ducks, runs).

export VISUAL=vi
crontab -e

(do some edits, finishing with ESCAPE)


And crontab -l should now show you your new crontab. If you prefer some other editor, set that in the VISUAL environment variable, and exit it as appropriate.

  • 2
    sir, I'm not used to vi, i use nano, that's why I'm having difficulties :) – user Sep 4 '11 at 16:40
  • I'm glad you've found a solution; but may I encourage you to ask the question you want answered in future? Perhaps a better question here would have been "how do I change the editor that's invoked when I type crontab -e"? People will be quick enough to offer alternatives if the thing you actually want seems impossible. – MadHatter Sep 4 '11 at 18:15
  • You can also hit ESC then :x to save and exit, or hit ESC then ZZ (that's shift+zz). – laebshade Sep 4 '11 at 18:36
  • sorry :D when I asked the question i wanted to figure out how to do it in vi and then quanta asked me to see what is my default editor, then i remembered to change it and do it easily with nano - I did not have that idea when i asked the question :D – user Sep 4 '11 at 19:57

Ctrl+x, answer by pressing y to save changes and Enter to confirm.


To exit vi editor:

Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file. The cursor moves to bottom of screen whenever a colon (:) is typed.

:x<Enter>   quit vi, writing out modified file to file named in original invocation
:wq<Enter>  quit vi, writing out modified file to file named in original invocation
:q<Enter>   quit (or exit) vi
:q!<Enter>  quit vi even though latest changes have not been saved for this vi call

esc-esc-:wq? Are you saying vi is the default editor, and you want nano instead?

Saving and quitting vi is outlined here: http://www.helpdesk.umd.edu/documents/4/4793/#a13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.