Emacs Lisp: Text Editing Functions
Here's the most used functions related to text editing.
Most functions insert to the position of current cursor. [see Cursor Position Functions]
(insert &rest ARGS)
Insert string into current buffer.
;; insert string at current cursor position (insert "sun and moon")
(insert-buffer-substring BUFFER &optional START END)
Insert text from another BUFFER into the current buffer.
(insert-into-buffer BUFFER &optional START END)
Insert text from current buffer into another BUFFER.
(insert-file-contents FILENAME &optional VISIT BEG END REPLACE)
Insert contents of file FILENAME into current buffer.
Delete n characters to the right. Use negative number to delete to the left.
;; delete 9 chars starting at cursor pos (delete-char 9)
Delete text btween 2 positions.
Tip: frequently used with
;; deleting text btween positions 59 and 896 (delete-region 59 896)
Delete all next in buffer, ignores Narrow to Region.
Delete between 2 positions and return the deleted text.
(delete-and-extract-region 3 20)