syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

You are here: Linux101 > Shell 101 > shell101_emacs

Linux Shell 101

Question:
In Linux101 how to install and use Emacs?

After I create the ann account and then learn vi, how to install and use Emacs editor ?

First I login as ann with a command like this:
ssh -YA ann@localhost
Or I just login to the ann account at the desktop GUI. Then I type these shell commands:
sudo apt-get install emacs
emacs hello.txt
If your Linux is setup well, you should see Emacs come up as a GUI editor.

If Emacs cannot figure out how to come up as a GUI editor, it will come up as a character-based editor.

I urge students to use the GUI editor if it is available and I advise them to stay away from Emacs if the GUI editor is unavailable.

For a character based editor, vi is a better choice than Emacs.

For a GUI editor, Emacs is best and it is easy to use.

I you have a Mac, GUI Emacs is always available and you can then use that Emacs to edit files on any Linux host that you can ssh into.

When Emacs comes up I just start typing into it and my text goes into the file I want to edit. In this case the file is hello.txt

When I am done, I just use my mouse on the top-menu to save.

It is much easier than vi. I do not need to memorize commands or know what mode I am in.

One thing I notice about people who use Emacs is they leave it open.

Usually with vi and other editors, I open, edit, save, and then close.

With Emacs I open, edit, save, and leave it open.

Emacs offers three features in addition to file-edit which encourage me to leave it open.

First, I can run a shell in Emacs and I can name the shell. If I have 17 shells open, I want them to be named and I want them displayed in a list of shells. Emacs does this feature very well.

Second, I use Emacs to operate on folders. The folder-UI in Emacs is superior to any folder-UI I have seen.

The way I operate Emacs is to stay in a tight triangle where I bounce between the three points: file-editor, folder-editor, and shell.

Shell programming without emacs is a chore. It feels like I am juggling three types of windows. When I move between window types it feels slow and mentally taxing.

Emacs offers another feature which speeds development. I run Emacs in GUI mode on my laptop and use it to edit files on Linux running on Amazon or other remote places.

This feature frees me from the chore of using vi on remote Linux instances.

Usually after I have Emacs up for a week it will contain hundreds of open files, folders, shells, and connections.

It is easy to bounce between any of them with a simple Emacs search mechanism.

If I tried doing the same thing with desktop windows I'd end up with a giant mess.

Sometimes I see a developer get lost and then distracted while searching for a window in a pile of 20 windows.

When I see this I am always tempted to say, 'You need to learn Emacs.'

The best way to learn Emacs is to start using it to write software.

When I want to learn a new Emacs feature, I describe the feature with an English question and then ask Google.

For example, 'How to send a command to Emacs?'

Answer: esc-x

If I know an Emacs command, do I need to type in the full name?

Answer: No, just some of it and then press tab.

How to start a Shell in Emacs?

Answer: esc-x shell

How to see a list of Emacs buffers?

Answer: esc-x buffer-menu

How to pick a buffer?

Answer: Move cursor to it, press return.

How to pick a file in a folder?

Answer: Move cursor to it, press return.

How to name a shell?

Answer: esc-x rename-buffer

Should I ignore most of the menu items?

Answer: Yes!, Just use the obvious items like Save, Undo, Copy, Paste, and Search.

How to open file on other host named bobcat?

Answer:
If I can ssh to bobcat, this should work:
esc-x find-file, enter, //bobcat:/home/ann/hello.txt

Can I run GUI-Emacs on my Mac and edit Linux files elsewhere?

Answer: Yes, this idea works well.

Where is the Emacs tutorial?

Answer: Click 'Help' in the top menu.

What should I put in my ~/.emacs file?

Answer: I like this syntax:
;;
;; .emacs
;;
;; I like to setup 3 'hot-keys':
;; esc-R
;; esc-m
;; ctrl-x s
;;

(global-set-key "\eR" 'rename-buffer)
(global-set-key "\em" 'buffer-menu-other-window)
(global-set-key "\C-xs" 'shell)

;; end




You are here: Linux101 > Shell 101 > shell101_emacs
You can ask questions in Dan's Machine Learning Class Forum:
https://groups.google.com/forum/#!forum/dan101

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me