User Tools

Site Tools


Using the emacs text editor



  • Add a screenshot
  • One process, multiple windows (FileNew Frame), multiple buffers
  • Emacs server…
  • Define some concepts:
    • frame, buffer, region
    • Parts of an emacs Frame (the graphical window or terminal screen occupied by Emacs is called Frame))
      • Menu bar
      • One or more windows displaying a Buffer
        • The last line of a window is the Mode Line that displays information about the Buffer above (e.g. file name, line/column number, editing mode, …
      • Echo Area or Mini Buffer, at the very bottom of the frame = Interaction field where informative messages are displayed (echo area) or where you enter information when Emacs asks for it (mini buffer)
      • Useful keys:
        • C-Z: iconify a Frame
        • F11: make frame fullscreen (toggle)
  • Automatic backup file
  • TAB key for auto-completion when opening files…
  • Using menus vs shortcuts
  • Key + Mouse shortcuts (e.g. CTRL+Left Mouse ⇒ Buffer Menu)
  • runs locally ⇒ no need for an X server
  • available on Linux/Win/Mac
  • highly customizable
  • splitting windows
  • WIN: configuring the Cascadia Code font

Installing emacs

Linux installation

Install the emacs package, if it is not already available

$ sudo apt install emacs
[sudo] password for your_login:
Reading package lists... Done
Building dependency tree
Reading state information... Done
emacs is already the newest version (1:26.3+1-1ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.

Mac installation

Install Aquamacs

Windows installation

emacs binaries for Windows

When installing emacs, you will need an account that can get elevated (i.e. administrator) permissions

At LSCE, use the .\admin account

  • Use winget to install emacs for Windows (optional winget details, for people who want to learn more):
    • Just type the folllowing, in a windows cmd, PowerShell or Terminal with elevated (i.e. administrator) permissions:
      winget install --id GNU.Emacs
  • IF the automated installation with winget does not work, download the most recent Windows installer from a gnu ftp mirror
    • Go to the most recent windows/emacs-XX/ folder (e.g. windows/emacs-29/)
    • Download the most recent emacs-XX.YY-installer.exe file (e.g. emacs-29.1_2-installer.exe) and execute it
  • If everything went well, you should have a new StartEmacs-XX menu that you can use to start emacs
    • If that's not the cas FIXME
  • You can work with the default emacs settings, but it is highly recommended to start with a nice existing emacs configuration file (if available)
  • If you need to work with remote files, emacs can automatically transfer files from your computer and remote servers, if configured properly
    Extremely useful
    • Install PuTTY, and configure a PuTTY profile for the desired host and user combination, so that emacs can use the PuTTY plink command to connect to remote servers (and transfer files)
      • Do not use space characters in the predefined PuTTY profile name!
        • mylogin_server (e.g. jyp_ssh1) is OK
        • but mylogin server will not work
    • Use the plinkx method when opening a remote file with emacs: /plinkx:mylogin_server:/path/to/file
      • Use exactly the same profile name as an existing PuTTY profile!
      • More details in FIXME
  • If you need to use the emacs ediff mode to compare text files
    Very useful
    • Install the Windows version of Gnu diffutils
      • Download and execute the Complete package, except sources installer (diffutils-2.8.7-1.exe as of August 2023) from
      • Be sure to uncomment the following line in your .emacs configuration file (and restart emacs). Otherwise emacs will not be able to find the diffutils binaries it needs for comparing text files
        • (setq exec-path (append exec-path '(“C:\\Program Files (x86)\\GnuWin32\\bin”)))
    • FIXME Find a recent compiled for Windows version of diffutils
      As of July 2023…
      • diffutils-3.10 is available (released in May 2023)
      • The 2.8.7-1 Win32 binaries are dated May 2004, but work perfectly fine!

emacs for Windows technical notes

These notes are only here for finding them easily, but you probably don't need them.
Just follow exactly the windows related instructions on this page!

Launching emacs

Linux launch

  • emacs some_text_file &
  • or just emacs &
  • FIXME error type if there is no X server, and option for forcing text mode (i.e NO GUI)

Windows launch

  • StartEEmacs

Mac launch


Using (and learning) emacs

Use C-g (CTRL+g) to abort or interrupt something in emacs

e.g. When you are searching forward with C-s, type C-g to exit the search

All the common functions of emacs are available from the pull-down menus at the top, but the real power comes from knowing (a few of) the keyboard shortcuts!

  • Understanding keyboard shortcuts:
    • C-x C-c means CTRL-x followed by CTRL-c, and will exit emacs
      • Same result as using FileQuit, just faster :-)
    • C-s means CTRL-s, and will Search forward
      • Hint: look for Incremental Search in the Reference Card for more information on searching!
    • C-g means CTRL-G and will abort the current emacs command/action (e.g. exit a forward search started with C-s)
    • C-z will iconify the emacs window!
      • Use C-x u (CTRL-x followed by u) or EditUndo for undoing the previous action!
    • M-f means Alt-f (or Esc followed by f if the keyboard has no Alt key), and will Move forward a word
  • Bonus! Many emacs shortcuts can be used in the shell or in Python, and will also make it possible to use emacs in text mode (if you get lost on a remote server without graphics…)
    • e.g. C-A and C-E to go to the beginning and end of a line
  • Copy-Cut-Paste
    • With a mouse: the usual Linux copy/paste behavior works:
      • Select and Copy text (at the same time) with the left button
      • Paste text with the middle button
      • Delete/Cut text (requires some practice): left-click at the beginning of the text you want to cut, then double-right-click at the end of the text
  • The official Guided Tour of Emacs is a nice web page quickly detailing the major concepts (buffer, region, mark, …) and shortcuts
    You can read this page, and later find some time for following the builtin tutorial (details below)
  • Built-in emacs tutorial, highly recommended! Spend one hour in the tutorial, and save hundreds of hours in the rest of your life!
    • HelpEmacs Tutorial
    • or HelpEmacs Tutorial (choose language)…
  • Reference cards, available in several languages
    • The Reference Card and the Survival Card mostly have the same content, just formatted a bit differently. The Reference Card is easier to read.
    • Emacs 21 Reference Card annotated by JYP (most useful shortcuts for beginners): emacs_jyp.pdf

emacs configuration file

  • The configuration file (and most of the emacs Packages) is written in Emacs Lisp
    • You can perfectly survive without knowing anything about lisp! Just don't forget opening and closing parentheses (( and )) when copy/pasting settings you find on the web, and remember that comments start with a ; character
    • The settings changed with the Options menu appear at the end of the configuration file
  • The easiest way to take changes into account is to restart emacs

Location of the configuration file

Configuration file name: .emacs

emacs knows (of course) where its .emacs configuration file is located! You can open the configuration file just by typing C-x C-f ~/.emacs and you can then check how your Home folder (~/) has been expanded

Related emacs (configuration) files and folders (e.g. .emacs.d/ folder) are located in the same place as the main configuration file

  • Linux:
    ~/.emacs: i.e. .emacs (dot-emacs) file in the current user's Home directory
  • Windows:
    If you want to access the emacs configuration files and folders, you will need to be able to see hidden folders and files!
    • Windows style path: c:\Users\your_login\AppData\Roaming\.emacs
    • Linux style path: c:/Users/your_login/AppData/Roaming/.emacs (or just ~/.emacs)
  • Mac

Example configuration file

  • Keyboard shortcuts defined by the example configuration file
    • C-x C-g: go to a specific line
    • Shift Left_Arrow and Shift Right_Arrow: go to the beginning/end of a line
      Same behavior as C-a and C-e, and the Home and End keyboard keys
    • Shift Up_Arrow and Shift Down_Arrow: go to the beginning/end of the buffer
    • Function keys
      • F1: Undo (lots of undos!!)
      • F2: Search and Replace
      • F3: fill-paragraph (i.e. automatically re-indent text or comments)
      • F4: indent the selected region (if indenting makes sense for the current buffer mode)
      • F5: comment out the selected region (comment style depends on the current buffer mode)
        • M-; can be used for commenting and un-commenting
      • F12: Repeat complex command (e.g. restart a previous query-replace operation)

Useful shortcuts

  • M-;: comment out selected lines
    This will automatically use the appropriate comment character for the current buffer mode, e.g. # for a Python script

Working with remote text files


Using the tramp mode

  • If you use the syntax below when opening a file (C-x C-f), emacs will automatically use the tramp mode to:
    • copy the remote text file (with scp) to your computer when you open it, so that you can edit the file locally
    • copy the edited text file (with scp) back to its original remote location when you save it (C-x C-s)
    • Opening a file on a remote server that you can reach directly:
      • /ssh:mylogin@server:/path/file
        • e.g. /
      • Or /plinkx:mylogin_server:/path/file on MS Windows, with an existing mylogin_server session defined in PuTTY
    • Opening a file on a remote server than you can only access through a gateway (e.g. file in a supercomputing center):
      • /ssh:user_A@gateway|ssh:user_B@target_server:/path/file
        • e.g. /|ssh:user_B@target_server:/path/file
      • Or /plinkx:mylogin_server|ssh:user_B@target_server:/path/file on MS Windows, with an existing mylogin_server session defined in PuTTY
    • More details:
  • Hint: if you use the recommended configuration file or have activated the '(recentf-mode t) mode, you can easily access recent files in FileOpen Recent without having to type the full access path again!


The tramp mode is quite complex and relies on connections to one or more remote computers using external programs and protocols. You may have to experiment a bit till you find the correct syntax and inline method to work with a particular remote server. Make sure you have read the prerequisite section!


  • If you get stuck (emacs is not responding), there is pr
    • Try aborting the current emacs command by typing C-g

Having fun with emacs

  • Use the built-in psychotherapist to solve your scientific problems (with M-x doctor). See also Fun and Games in Emacs
    I am the psychotherapist.  Please, describe your problems.  Each time
    you are finished talking, type RET twice.
    My climate model does not work
    Why do you say your climate model does not work?
    I get wrong results
    Is it because of your plans that you say you get wrong results?

emacs documentation

Updating emacs




Using winget upgrade for updating emacs on Windows unfortunately does not work yet (August 2023). The easiest way to update Emacs is:

  • Check the version of the installed Emacs
    • In the Start menu: StartEEmacs-version (e.g. Emacs 28.2)
    • In a running Emacs: Help menu ⇒ About Emacs
  • Use winget show in a PowerShell to determine (all) the available versions
    • PS C:> winget show --id GNU.Emacs --versions
      Found GNU Emacs [GNU.Emacs]
  • If you want/need to update Emacs (after making sure it is not running)
    • Uninstall it with: StartEEmacs-versionUninstall
      Your emacs configuration file and other files you have installed will not be removed!

[ PMIP3 Wiki Home ] - [ Help! ] - [ Wiki syntax ]

other/emacs_doc.txt · Last modified: 2023/12/06 16:55 by jypeter