Emacs: New Empty Buffer 🚀

By Xah Lee. Date: . Last updated: .

To open a new buffer/file in emacs, Alt + x switch-to-bufferCtrl + x b】, then type a new name. [see Emacs: Switch Buffer]

Here's a command to open a new empty buffer, without prompting for a name.

(defun xah-new-empty-buffer ()
  "Create a new empty buffer.
Returns the buffer object.
New buffer is named untitled, untitled<2>, etc.

Warning: new buffer is not prompted for save when killed, see `kill-buffer'.
Or manually `save-buffer'

URL `http://xahlee.info/emacs/emacs/emacs_new_empty_buffer.html'
Version: 2017-11-01 2022-04-05"
  (let ((xbuf (generate-new-buffer "untitled")))
    (switch-to-buffer xbuf)
    (funcall initial-major-mode)

You can give it a easy key such as F7. [see Emacs: How to Define Keybinding]

Start Emacs with Empty Buffer

(setq initial-buffer-choice 'xah-new-empty-buffer)