Complete Guide to Emacs: Setting Up a Modern Development Environment
May 04, 2014
I always wanted to use Emacs. Yesterday, I wanted to have a good JavaScript/Node REPL in my editor. Though I had always used Vim for the last 5 years, setting up a REPL in Vim is not very easy. So I decided to give Emacs a try, and so far I am enjoying using Emacs.
Here is a guide that would help you set up Emacs.
First of all, if you are on Mac, install Emacs for OSX from here. You could easily install the GUI version of Emacs for other platforms too.
My Emacs Config
This is my Emacs config which can be used for development in the following technologies:
- Ruby / Ruby on Rails
- CSS / LESS / SASS / SCSS
- HAML / Markdown / Textile / ERB
- Clojure (via nrepl)
- JavaScript / CoffeeScript
- Python
- PHP
- Haskell
- Erlang
- Common Lisp (with Slime)
In particular, there’s a nice config for tab autocompletion, and flycheck is used to immediately highlight syntax errors in Ruby, HAML, Python, JavaScript, PHP, and a number of other languages.
Demo
This is my Emacs live in action:
Requirements
- Emacs 23 or greater (note that Emacs 24 is required for some functionality, and will likely become the minimum required version some time soon.)
Installation
To install, clone this repo to ~/.emacs.d, i.e., ensure that the
init.el contained in this repo ends up at ~/.emacs.d/init.el:
git clone https://github.com/vinitkumar/.emacs.d.git ~/.emacs.d
Upon starting up Emacs for the first time, further third-party packages will be automatically downloaded and installed.
Adding Your Own Customization
To add your own customization, use M-x customize and/or
create a file ~/.emacs.d/lisp/init-local.el which looks like this:
... your code here ...
(provide 'init-local)
Tips for Using These Emacs Settings
If you want to use my settings straight out of the box, here are some things to note:
-
I recommend starting with a blank Emacs + Technomancy’s better-defaults package, and then dig through this repo for useful nuggets, instead of forking it directly.
-
The key bindings are optimized for a Norwegian keyboard layout.
-
Start by reading up on all the cool stuff in key-bindings.el.
-
You quit Emacs with
C-x r q, mnemonic Really Quit. -
Find file in project with
C-x o, in dir withC-x C-f, recent withC-x f -
Add your user- and project-specific stuff in .emacs.d/users/[machine name]/*.el
-
C-his rebound to backspace, like in the shell. Get help onF1instead. -
Autocomplete with
C-.(autocomplete entire lines withC-:) -
expand-region is your friend. Find its bound key by doing
F1 f er/expand-region -
Undo with
C-_and redo withM-_. Watch the undo-tree withC-x u -
Quickly jump anywhere in the buffer with
C-øthen the starting letter of a word. -
Indent and clean up white space in the entire buffer with
C-c n -
On a Mac, the Meta key
Mis bound to Command. -
I recommend rebinding Caps Lock to Ctrl and use that instead of the often badly placed Ctrl key.
-
Watch emacsrocks.com
Survival Guide for the First Week of Emacs
When you start using Emacs for the first time, your habits fight you every inch of the way. Your fingers long for the good old familiar keybindings. Here’s an overview of the most commonly used shortcuts to get you through this pain:
CShorthand for the Ctrl keyMShorthand for the Meta key (bound to Cmd on my Mac settings)SShorthand for the Shift key
Files
C-x C-fOpen a file. Starts in the current directoryC-x fOpen a recently visited fileC-x oOpen a file in the current project (based on .git ++)C-x C-sSave this fileC-x C-wSave as …C-x C-jJump to this file’s current directoryC-x bSwitch to another open file (buffer)C-x C-bList all open files (buffers)
Cut, Copy, and Paste
C-spaceStart marking stuff. C-g to cancel.C-wCut (aka kill)C-kCut till end of lineM-wCopyC-yPaste (aka yank)M-yCycle last paste through previous killsC-x C-yChoose what to paste from previous killsC-@Mark stuff quickly. Press multiple times
General
C-gQuit out of whatever mess you’ve gotten yourself intoM-xRun a command by nameC-.AutocompleteC-_UndoM-_RedoC-x uShow the undo-treeC-x mOpen magit. It’s a magical git interface for Emacs
Navigation
C-arrowMove past words/paragraphsC-aGo to start of lineC-eGo to end of lineM-g M-gGo to line numberC-x C-iGo to symbolC-sSearch forward. PressC-sagain to go further.C-rSearch backward. PressC-ragain to go further.
Window Management
C-x 0Close this windowC-x 1Close other windowsC-x 2Split window horizontallyC-x 3Split window verticallyS-arrowJump to window to the left/right/up/down
Help
F1 tBasic tutorialF1 kHelp for a keybindingF1 rEmacs’ extensive documentation
Credits & Inspiration
This config is totally based on this repo by Mr. Steve Purcell. But this might diverge with time and my personal taste.
The Survival guide has been taken from the .emacs.d project of Mr. Magnar Sveen