Published on

How to setup Emacsclient

Setting up emacsclient allows one to open and edit files in an already running Emacs instance, which is especially useful when working with multiple files or as part of a scripted workflow.

  1. Ensure Emacs Server is Running:

    • Start Emacs if it's not already running.

    • In Emacs,start the server by evaluating (server-start) in the scratch buffer or by adding it to Emacs configuration (init.el or .emacs):

      (server-start)
      
  2. Set the EDITOR Environment Variable:

    • Add the following line to shell profile configuration file (e.g., ~/.bashrc, ~/.zshrc, etc.), which sets the EDITOR environment variable to emacsclient:

      export EDITOR="emacsclient -c"
      
    • Reload shell configuration to apply the changes (e.g., source ~/.bashrc).

  3. Alias for Simplicity (Optional):

    alias ec="emacsclient -c"