Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

#!/bin/sh

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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