Set emacs -nw as default editor
Solution 1
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
Solution 2
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.
Solution 3
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
[core]
editor = emacsclient -t -a=\\\"\\\"
Related videos on Youtube
gsingh2011
Updated on September 18, 2022Comments
-
gsingh2011 almost 2 years
When editing files like
sudoers
, I want to use emacs instead of nano. So I ran this commandsudo 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 withemacs -nw
. How can I do this? I'm on Ubuntu 12.04.-
Admin over 7 yearsThis 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.
-
-
sam almost 10 yearsFor those who don't use update-alternatives featured systems,
chmod +x /usr/local/bin/emacs-nw
andexport EDITOR='emacs-nw'
in.bashrc
do the trick. -
Manolete over 8 yearsAfter setting
EDITOR
how would you open Emacs in graphical mode? -
Kyrremann about 8 years@Manolete you can use
command emacs
, this will run Emacs without aliases and such. Of course you can alsounalias emacs
for a session. -
haziz about 8 years@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. -
vaer-k almost 6 yearsSimply 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? -
Admin about 2 years> 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 inmc
is set tofalse
so thatF4
invokes$EDITOR
)