Elisp: Text Editing Functions

By Xah Lee. Date: . Last updated: .

Here's the most used functions related to text editing.

You should memorize these by heart.

Insert Text

;; insert string at current cursor position
(insert "sun and moon")

(info "(elisp) Text")

Delete Text

delete-char → delete n characters to the right. Argument can be negative, to delete to the left.

;; delete 9 chars starting at cursor pos
(delete-char 9)

delete-region → delete text btween 2 positions.

;; deleting text btween positions 59 and 896
(delete-region 59 896)

Delete All Buffer Text

erase-buffer → delete all next in buffer, ignores narrow-to-region.


Delete and Extract Text

delete-and-extract-region → Delete between 2 positions and return the deleted text.

(delete-and-extract-region 3 20)

Get Text from Buffer to String

Elisp: Get Buffer String


Elisp: String Functions

Elisp Basic Functions

  1. Elisp: Cursor Position Functions
  2. Elisp: Text Editing Functions
  3. Elisp: String Functions
  4. Elisp: Buffer and File Functions
  5. Elisp: File and Directory Functions
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.