When editing files like sudoers, I want to use emacs instead of nano. So I ran this command

sudo update-alternatives --config editor

And I selected emacs. The only issue is I like emacs in no window mode (the -nw flag) and I've aliased emacs as emacs='emacs -nw' so that I can use no window mode in normal use, but I don't know how to get my default editor to be in no window mode.

In other words, I need to get the command sudo visudo and similar commands that open up editors to open the file with emacs -nw. How can I do this? I'm on Ubuntu 12.04.

  • This is unrelated, but if you're intending to use `emacs -nw' as your default terminal editor, you may want to look into emacsclient and running emacs as a daemon. Otherwise, I would think that it would be far too slow to startup. With an emacs server, it's practically instant startup, and not difficult to set up.
    – Dodgie
    Nov 4, 2016 at 17:41

3 Answers 3


Create a script that starts emacs with -nw flag, e.g. /usr/local/bin/emacs-nw.


emacs -nw "$@"

Install it with update-alternatives --install.

sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/emacs-nw 2

Configure editor to be your new script.

sudo update-alternatives --set editor /usr/local/bin/emacs-nw
  • 2
    For those who don't use update-alternatives featured systems, chmod +x /usr/local/bin/emacs-nw and export EDITOR='emacs-nw' in .bashrc do the trick.
    – smonff
    Sep 6, 2014 at 19:54
  • 1
    Simply updating the EDITOR shell variable to call emacs -nw is more traditional and doesn't involve all this weird file creation for such a simple task. Why is this better?
    – vaer-k
    Aug 9, 2018 at 20:13
  • > Why is this better? In my case because, -nw or any other flags are ignored, when editor is invoked from midnight commander (use internal editor flag in mc is set to false so that F4 invokes $EDITOR) May 20 at 20:03

Add the following to your ~/.bashrc file (or the config file for your shell if it is not Bash).

export EDITOR="emacs -nw"

This should set (and export) an env variable setting your default editor as Emacs in non-graphical mode.

  • After setting EDITOR how would you open Emacs in graphical mode?
    – Manolete
    Mar 2, 2016 at 14:59
  • 2
    @Manolete you can use command emacs, this will run Emacs without aliases and such. Of course you can also unalias emacs for a session.
    – Kyrremann
    May 4, 2016 at 7:52
  • 1
    @Manolete Actually launching emacs with emacs at the command line or clicking on it's icon will still launch the graphical form. The command above in my post just sets the EDITOR enviromental variable to "emacs -nw" it actually does not create an alias. It just tells the shell that your preferred editor is emacs -nw. emacs will still launch the graphical form.
    – haziz
    Jul 3, 2016 at 11:11

I have following setting in my ~/.bashrc

export EDITOR="emacsclient -t -a=\"\""

This will first try to connect emacs daemon server if it is already started, otherwise start daemon server first then connect again.

Similarly, I have following setting in my ~/.gitconfig

    editor = emacsclient -t -a=\\\"\\\"

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.