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 since last 5 years still setting up a REPL in Vim is not very easy. So I decided to give Emacs a try and till now I am enjoying using Emacs.
Here is a guide that would help you to setup 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 could be used for development in 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-h
is rebound to backspace, like in the shell. Get help onF1
instead. -
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
M
is 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:
C
Shorthand for the ctrl-keyM
Shorthand for the meta-key (bound to cmd on my mac settings)S
Shorthand for the shift-key
Files
C-x C-f
Open a file. Starts in the current directoryC-x f
Open a recently visited fileC-x o
Open a file in the current project (based on .git ++)C-x C-s
Save this fileC-x C-w
Save as …C-x C-j
Jump to this files’ current directoryC-x b
Switch to another open file (buffer)C-x C-b
List all open files (buffers)
Cut copy and paste
C-space
Start marking stuff. C-g to cancel.C-w
Cut (aka kill)C-k
Cut till end of lineM-w
CopyC-y
Paste (aka yank)M-y
Cycle last paste through previous killsC-x C-y
Choose what to paste from previous killsC-@
Mark stuff quickly. Press multiple times
General
C-g
Quit out of whatever mess you’ve gotten yourself intoM-x
Run a command by nameC-.
AutocompleteC-_
UndoM-_
RedoC-x u
Show the undo-treeC-x m
Open magit. It’s a magical git interface for emacs
Navigation
C-arrow
Move past words/paragraphsC-a
Go to start of lineC-e
Go to end of lineM-g M-g
Go to line numberC-x C-i
Go to symbolC-s
Search forward. PressC-s
again to go further.C-r
Search backward. PressC-r
again to go further.
Window management
C-x 0
Close this windowC-x 1
Close other windowsC-x 2
Split window horizontallyC-x 3
Split window verticallyS-arrow
Jump to window to the left/right/up/down
Help
F1 t
Basic tutorialF1 k
Help for a keybindingF1 r
Emacs’ 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 .emacs.d project of Mr. Magnar Sveen