Before switching to Emacs, I had been using Vim. As I do in Emacs, I used to add a bunch of plugins to my .vimrc.

One Vim plugin I miss in Emacs is surround. As the name implies, it is a plugin for editing parentheses and brackets. I knew there existed Emacs packages for that purpose, but I did not think about how I want to do it until recently.

After doing some research and trying out packages, I ended up with the following plan for editing parentheses1:

  • To enclose an active region with a pair of parentheses, you can simply type ( in most modes. This is supported by electric-pair-mode, lispy-mode, etc.
  • To add/delete/change brackets around the point, you can use embrace. I bind M-i to embrace-commander, but I often forget using this command.
  • To edit contents inside the surrounding quotes/brackets, you can use sp-change-enclosing from smartparens. I bind C-c e to this command2.

You can also use expand-region for killing text inside/with a bracket pair.

Other options include isolate and siege-mode. I didn’t choose those packages because the configuration described above would work for most cases.

Note that this is not about editing lisp code in Emacs. I use lispy for that purpose.

This workflow is still not as consistent as in vim-surround. I must admit that vim can be more efficient than Emacs in some situations for text editing, but I am using Emacs mostly because I need an application that is capable of everything. I want to know if there is a more elegant way to editing parentheses.


  1. I am not an evil user, so I did not consider any evil-based packages. [return]
  2. To use this command in minibuffers, you need to add smartparens-mode to minibuffer-setup-hook. [return]