An Introduction to Emacs: Everything You Need to Know to Get Started
Emacs is a pain in the butt for a beginner to learn how to use, and it shouldn’t be. For some reason the learning curve just to edit files and navigate your system is incredibly steep for such a simple task, when it’s actually very simple. In This article you’ll learn everything you need to know to understand how emacs works, and how to get work done in emacs quickly, even as a beginner.
In order to use Emacs, you’ll need to understand keyboard shortcuts. C stands for “Control” and M stands for “Alt”. Here’s a couple examples.
Ex. 1: C-x s = Press and hold Control, then tap x. release everything, then tap s.
Ex. 2: M-x describe-coding-system Enter = Press and hold ALT, then tap x. release everything. type describe-coding-system. press RETURN/ENTER
Ex. 3: C-x C-c = Press and hold Control, then tap x. release everything. Press/hold Control and tap c. release everything.
What is Emacs?
Emacs is an extremely powerful text editor that can be used efficiently for everything from writing code, chatting in IRC, debugging, managing files, running terminal commands, browsing the internet, and much more. The running joke is that “Emacs is a terreble Text editor, but a great Operating system”. Many Emacs fanatics “live” in emacs and do everything inside it.
The easy part! There are several “forks” of Emacs, but we’ll stick with the original for now. Just head over to the Emacs download page and select the download for your OS. https://www.gnu.org/software/emacs/download.html
If you’re on a Mac, I recommend you use HomeBrew to install Emacs. Install Homebrew and run this in your terminal:
brew install emacs --with-cocoa
If you use a Linux Distro, I recommend installing with your package manager.
Ubuntu: $ sudo apt-get install emacs
Gentoo: $ emerge –ask emacs
Hopefully the installation goes smoothly. Once it’s installed, Start Emacs with:
Or click on the emacs icon if you have one. Hopefully you can figure out how to start an application.
Moving around the FileSystem With Dired
In order to actually get work done with emacs, you need to understand “Dired”. This is one of the ways you move around in your computer, add, delete, edit, and view both files and folders. Here’s a video to help you out, followed by some commands written below the video!
|C-b||Move cursor backward|
|C-f||Move cursor forward|
|C-n||Move cursor downward|
|C-p||Move cursor upward|
|Arrow Keys||Alternative Moving|
Useful Dired Commands
|C-x d Enter||Open Dired|
|C-x C-f||Find File (Create New File)|
|+ (Shift and Equal sign)||Create New Directory|
|d||Mark file or directory for deletion (x runs deletion)|
|C-s||I-search (C-s again for next instance)|
|C-s C-r||Search backward. type C-s, then search term, then C-r to search backward|
|R (Capital R)||Rename File. Marking multiple files before Shift+R will MOVE all files.|
|m (lowercase m)||Mark a file. Used for actions on multiple files at once|
|u||unmark a file/directory|
|x (lowercase)||Run actions on the files|
|C-x C-s||Save File|
|C-g||Quit current command (if you made a typo during a command)|
|C-x 5 2||Create new Emacs Frame|
|C-x 5 o (lowercase letter)||Cycle through open Emacs frames|
|C-x 5 0 (zero)||Delete current Emacs Frame|
|C-x 2||Open a new Emacs Window below current Emacs window|
|C-x 3||Open new Emacs window beside current window|
|C-x o (lowercase letter)||Cycle through open Emacs windows|
|C-x 0 (zero)||Close Current Emacs window|
|C-x C-b||Open Buffer List (Switch between recently opened files)|
|C-x b Enter||Switch to Emacs Buffer (Must know name and type in buffer name)|
Installing & Configuring Packages in Emacs:
Being able to customize Emacs is what makes it so dang cool. You’re basically creating your very own editor from scratch, only you have a friendly community who shares their creations with you. Okay, here’s how you configure emacs.
~/.emacs & ~/.emacs.d
The .emacs file located (usually) in your home directory is where all of the configuration for your editor goes. The list of all packages used, custom keybindings, and all customizations go in the .emacs file.
The .emacs.d folder is where all your package source code belongs. Every package you install needs a place to live, and the .emacs.d directory (again located in the home directory) is the perfect place for all the source code to live!
Melpa is a package manager. It helps you keep all the emacs packages up to date and installed on your system. When you can, it’s recommended to use Melpa.
Useful Melpa Commands: (Must install Melpa first)
|M-x package-list-packages||List all Emacs packages available in Melpa|
|M-x package-install Enter (type name of package)||Install specific package|
|i||Mark a Melpa package for installation|
|d||Mark a package for un-installation|
|x||run the command on packages marked|
|M-x eval-buffer (run command in .emacs buffer)||Refreshes the current buffer|
Fast Emacs Window & Frame switching with WindMove & FrameMove
Code for WindMove & FrameMove Home/Vim keybindings
;; ;; Window & Frame Switching with WindMove and FrameMove ;; (when (fboundp 'windmove-default-keybindings) (windmove-default-keybindings)) ;; Remap windmove keys to home keys (global-set-key (kbd "M-h") 'windmove-left) (global-set-key (kbd "M-j") 'windmove-down) (global-set-key (kbd "M-k") 'windmove-up) (global-set-key (kbd "M-l") 'windmove-right) (require 'framemove) (windmove-default-keybindings) (setq framemove-hook-into-windmove t) ;;Hook framemove into windmove keys ;; Common lisp stuff to fix windmove/framemove (require 'cl) ;;used to Fix error if theres an error with above code ;; ;; End of Windmove & Framemove setup ;;