Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active November 10, 2024 14:29
Show Gist options
  • Save amirrajan/195c3c87d811586126e85c5e3dbf7a06 to your computer and use it in GitHub Desktop.
Save amirrajan/195c3c87d811586126e85c5e3dbf7a06 to your computer and use it in GitHub Desktop.
Minimal Emacs configuration for Windows and Mac (Vim bindings and leader key)

Here is a minimal setup that works on Windows and Mac (yes I use Emacs on Windows and it works well).

;; using an editor you are comfortable with
;; create c:/Users/USERNAME/AppData/Roaming/.emacs.d/init.el
;; and paste these contents in there:

;; NOTE: depending on how you start up emacs, your home directory may
;;       be different than the one above. Your initialization file 
;;       needs to be saved at ~/.emacs.d/init.el (however that is mapped
;;       for your environment)

;; remove welcome screen
(setq inhibit-startup-message t) 
(setq initial-scratch-message nil)

;; initialize package installation
(require 'package)

;; add package repositories
(push '("melpa" . "http://melpa.org/packages/") package-archives)
(push '("org" . "http://orgmode.org/elpa/") package-archives)
(push '("melpa-stable" . "https://stable.melpa.org/packages/") package-archives)

;; initialize
(package-initialize)

;; retrieve repos if needed
(when (not package-archive-contents)
  (package-refresh-contents))

;; install vim bindings
(package-install 'evil)

;; install leader key override
(package-install 'evil-leader)

;; make sure vim bindings are enabled on startup
(evil-mode 1)
(global-evil-leader-mode)

(setq evil-want-C-i-jump nil)

;; assign leader key
(evil-leader/set-leader ",")

;; wire up <leader> p, and <leader> q to invoke custom functions
;; just as an example of how you can do this
(evil-leader/set-key
 "q" 'hello-world
 "p" 'byebye-world)

;; example of a custom method
(defun hello-world ()
  ;; marks the method as callable through the mini buffer
  ;; for example, you can invoke this function by typing
  ;; the following in the minibuffer
  ;;   :hello-world
  (interactive)
  (message "hello world"))

(defun byebye-world ()
  (interactive)
  (message "bye bye world"))

After you have this initial config - and your environment bootstrapped with modal editing as the gods intended - you can start digging into installing other packages. Some plugins I use/enjoy:

  • use-package for better plugin/configuration organization
  • avy is like Ace Jump for VIM.
  • magit the best fucking git interface I have ever used (fugitive would be the vim analog)
  • You can get additional ideas from my Emacs setup

The whole point of using Emacs is to have a hackable environment so you can make the editor your own. Bite that bullet now and learn how to do that. Over your career, the customizations you add will pay back in spades. If you don't care about crafting an environment that becomes an extension of your mind, use an easier/batteries included editor like VS Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment