Experimenting with Emacs
Having become accustomed to the Vim editor in the ~16 years I’d been using Linux, I hadn’t really bothered with Emacs, though I’d come across numerous mentions of it, and many commenters on Hacker News say it’s their go-to editor.
Vim is considerably more lightweight (about 300MB more lightweight), and it has many things that apparently aren’t included in the default installation of Emacs - syntax highlighting, code folding, tabs, symmetric encryption, etc., for example. There’s a very good chance some variant of Vim will be available on a server, if we need to SSH into it and modify something. And the config file appears more comprehensible. I know I’ve barely scratched the surface of Emacs, but still…
The two editors are sort of similar. Both can be used entirely in the terminal. As with Vim, the user edits the contents of a buffer. In other words, everything in Emacs is in-memory until it’s explicitly written to a file - as I understand it, there’s no memory-disk swapping or auto-save (this can be configured in .vimrc). Both have ‘interactive’ modes that enable the user to enter commands, and I think the keybinding for that in Emacs is Alt+x.
Open or Create a New File
The same keybinding can be used to open or create a new file:
Ctrl+x Ctrl+f
Emacs will prompt for a file name. Pressing the Enter key will cause Emacs to display a file browser. Entering the name of a file that doesn’t exist yet will create a new buffer.
Saving a Buffer and/or Closing Emacs
- Close editor:
Ctrl+x Ctrl+c - Write buffer to file:
Ctrl+x Ctrl+s
Manipulating Text
We want to be able to copy and paste text. Use Ctrl+Space and the arrow keys to select a region of text. The Ctrl+n and Ctrl+p keys can also be used to move the cursor up and down lines.
The following can then be used:
- Copy text:
Alt+w - Paste text:
Ctrl+y
Syntax Highlighting
Options are limited by default to a handful of languages: Bash, Python and HTML,etc. The following keybinding is used for syntax highlighting Python code:
Alt+x
Then: python-mode
Windows
Multiple windows can be displayed in Emacs.
- Create additional window:
Ctrl+x 2 - Create third window:
Ctrl+x 3 - Switch window:
Ctrl+x o - Close current window:
Ctrl+x 0