Emacs: Save Cursor Position

By Xah Lee. Date: . Last updated: .

You can save the cursor position for every file you opened. So, next time you open the file, the cursor will be at the position you last opened it.

Put this code in your emacs init file:

;; remember cursor position, for emacs 25.1 or later
(save-place-mode 1)

For before emacs 25.1, the syntax is different. Use this code:

;; remember cursor position
(if (version< emacs-version "25.0")
    (progn
      (require 'saveplace)
      (setq-default save-place t))
  (save-place-mode 1))

By default, the cursor position info is saved at ~/.emacs.d/places

The file location is controlled by the variable save-place-file.

saveplace.el is written by Karl Fogel since 1993. Karl is also the author of Emacs's Bookmark Feature. [see Emacs: Bookmark] Thanks Karl.

Manage Windows Topic

  1. Emacs: Split Windows Basics
  2. Emacs: Save Split Windows Configuration
  3. Emacs: Effective Windows Management
  4. Emacs: Make Buffer Flow Side-by-Side
  5. Emacs: Restore Opened Files, Windows Config
  6. Emacs: Set Default Window (frame) Size
  7. Emacs: Save Cursor Position

Emacs Customization

  1. How to Set Emacs's User Interface
  2. Emacs: How to Install Packages Using ELPA, MELPA
  3. How to Install Emacs Package Manually
  4. Emacs: How to Define Keys
  5. Emacs: M-x customize Tutorial
  6. Emacs: Set File to Open in a Major Mode
  7. Emacs: Organize Init File
  8. Emacs: Byte Compile Elisp Files
  9. Emacs: What's Hook?
  10. Emacs: Set Environment Variables within Emacs
  11. Elisp: Determine OS, Emacs Version, Machine Host Name
  12. Elisp: Check If a {function, variable, feature} is Defined/Loaded
  13. Emacs: Set Default Window (frame) Size
  14. Emacs: Font Setup
  15. Emacs: Set Color Theme
  16. Emacs: Save Cursor Position
  17. Emacs: Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
  18. Emacs: Stop Cursor Going into Minibuffer Prompt
Like my tutorial? Put $5 at patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

Ask me question on patreon