**Edit: My final Emacs conf is here. **
Check here: https://www.gnu.org/software/emacs/download.html
For Windows, go to this mirror site, and download emacs-27.2-x86_64.zip and extract it.
For macOS, use homebrew to install Emacs (
brew install --cask emacs)
How to Run?
- Windows: Go to extracted folder, run
- macOS: Run
emacsfrom command line or search
Emacs.appand run it.
Note to run emacs in maximized window, add following config to emacs config file:
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
- Run in maximized window: https://emacs.stackexchange.com/a/3017/23435
To check config file path, run
C-H v user-init-file RET (
RET is return
Reload config: note that it is not possible to entirely reload config, the best
way is to restart your emacs. Open
init.el, and run
- Show conf file path: https://stackoverflow.com/a/192097/6064933
- Reload config without quit: https://stackoverflow.com/a/167719/6064933
I am not a purist guy which only uses the builtin features of and editor and refuses to add plugins or packages.
Package is to Emacs what plugin is to Vim.
The builtin way
To install packages, run
M-x package-install, we are prompted to type the
package name we want to install. Type the package name, and the package shall
Sometimes, due to bad network connection, emacs hangs forever when trying to connect to its package repo, and we see the following message:
Contacting host: elpa.gnu.org:443
In this case, we can change the package repo URL
(add it to
;; this is just an example (setq package-archives '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/") ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
One disadvantage of using builtin package management is that it can not install a package automatically if its hasn’t been installed. We need to write a few lines of code in config file.
Using 3rd party package manager
Aside from the builtin way to install packages, we can also use 3rd party package managers, for example, straight.el.
To install straight.el, just put the following script to
(defvar bootstrap-version) (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) (bootstrap-version 5)) (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" 'silent 'inhibit-cookies) (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage))
To install a package, add the following statement to init.el:
(straight-use-package 'some-package) ;; for example, to install company-mode, use the following (straight-use-package 'company)
Straight.el will install a package if it has not been installed yet.
Color, theme, modeline
We can surly customize the look of Emacs via handcraft, e.g., change background color and foreground color:
(add-to-list 'default-frame-alist '(foreground-color . "#E0DFDB")) (add-to-list 'default-frame-alist '(background-color . "#102372"))
More advanced way to customize color is to use or install a color theme. Emacs comes with several builtin themes.
To load a theme, type
A-x load-theme, and then type a theme name, for example,
doom-one, or we can add to config:
(load-theme 'doom-gruvbox t nil)
To show currently enabled themes, run
c-h v and type
- Delete a line:
- Go to line beginning and end:
- Yank selected text and paste:
I find the editing experience in Emacs highly inferior to that of Vim. So We can use emacs-evil:
(straight-use-package 'evil) ;; enable evil mode (evil-mode 1)
- delete a line: https://stackoverflow.com/a/3958568/6064933
Window and buffer
- open a horizontal split:
- open a vertical split:
- close a buffer:
- close a window:
- open a file:
- create a new file: same as
- save a file:
- quit emacs:
- Open a buffer:
- To show config file path, run
M-:, then type
(buffer-file-name)to show config path.
- close buffer: https://stackoverflow.com/q/207510/6064933
- close a windows: https://stackoverflow.com/q/17961449/6064933
- show file path: https://stackoverflow.com/a/17415557/6064933
c-h ? gives an overview of the help system.
- Check the value of a variable:
c-h v <variable-name>
- Check function doc:
- Check which command a key binds to:
Add the following to your emacs conf:
(setq completion-cycle-threshold 1)
disable toolbar, menu bar, scrollbar
Toolbar, menu bar and scrollbar are ugly and take precious space. Let’s disable them all together:
(menu-bar-mode -1) (toggle-scroll-bar -1) (tool-bar-mode -1)
Show line number and relative number
Like what vim does:
(global-display-line-numbers-mode) (setq display-line-numbers-type 'relative)
What they call statusline in Vim, we call it modeline in Emacs. IMO, they are very similar concepts. We can use doom-modeline to help use customize the modeline.
First, we need to install some special icon that doom-modeline
M-x all-the-icons-install-fonts to install the icon
fonts. Then install doom-modeline:
- check current themes: https://superuser.com/a/320289/736190
For Emacs 27, add the following setting to
show trailing white space
Add following config:
(setq-default show-trailing-whitespace t)
We can use package company to enable
auto-completion for functions and options etc. Add the following
;; enable company mode in all buffers (add-hook 'after-init-hook 'global-company-mode) ;; use tab and s-tab to cycle forward and backward completion items (add-hook 'after-init-hook 'company-tng-mode)
If you have used Vim, you may be familiar with fzf.vim or LeaderF or telescope.nvim, depending which Vim distribution you are using. In Emacs, we can use ivy.
Here is a minimal config:
(straight-use-package 'ivy) (straight-use-package 'counsel) ;; enable ivy mode by default (ivy-mode 1)
Then ivy will be automatically enabled when you open file/buffer or
run commands. Note that the default fuzzy search behavior of ivy is
different from that of LeaderF or fzf. For example, to search
package-install in ivy, you can type
pac ins, but not
the space between is important.
Parentheses: highlight and insert
To highlight matching parentheses, add the following config:
;; show matching parentheses (show-paren-mode t) ;; the style for matching parentheses (set-face-background 'show-paren-match "#ff0000") (set-face-attribute 'show-paren-match nil :weight 'bold :underline t :overline nil :slant 'normal)
To insert matching parentheses automatically, install package smartparens:
(straight-use-package 'smartparens) ;; enable smartparens mode (smartparens-global-mode t)
To change, delete, add matching pairs easily, there is also evil-surround, mimicking the behavior of vim-surround by Tpope.
- show matching parentheses
custom-set-faces is added automatically to
After installing packages,
init.el is automatically updated and
custom-set-faces. We can use the following setting to
disable this behavior:
(setq custom-file (locate-user-emacs-file "custom.el")) (load custom-file)
Change backup directory
By default, Emacs saves a backup file in the same directory as the current file, which pollutes the current working directory. We can move the backup directory to a centralized directory:
;; change backup settings (setq backup-directory-alist '(("." . "~/.cache/emacs-backups")))
After learning and trying Emacs for one day, I would say that Emacs is truly a great GUI editor which has some really cool features. For example, in Emacs, you can set different font style (size, bold, italic, font family etc.) to different texts in the same buffer, which org-mode used for beautiful type-setting inside Emacs1. You can also get the vscode-like experience via customize groups.
However, when it comes to editting text and navigation, I think Vim/Nvim is still the king, the proof of which is apparent since we have got evil-mode in Emacs.
- awesome emacs: https://github.com/emacs-tw/awesome-emacs
Sadly, I do not think any Nvim GUI can do this or come even close to org-mode. ↩︎
License CC BY-NC-ND 4.0