Function: evil-write
evil-write is an interactive and byte-compiled function defined in
evil-commands.el.
Signature
(evil-write BEG END &optional TYPE FILE-OR-APPEND BANG)
Documentation
Save the current buffer, from BEG to END, to FILE-OR-APPEND.
If FILE-OR-APPEND is of the form ">> FILE", append to FILE instead of overwriting. The current buffer's filename is not changed unless it has no associated file and no region is specified. If the file already exists and the BANG argument is non-nil, it is overwritten without confirmation.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-commands.el
;;; Ex
(evil-define-operator evil-write (beg end _type file-or-append &optional bang)
"Save the current buffer, from BEG to END, to FILE-OR-APPEND.
If FILE-OR-APPEND is of the form \">> FILE\", append to FILE
instead of overwriting. The current buffer's filename is not
changed unless it has no associated file and no region is
specified. If the file already exists and the BANG argument is
non-nil, it is overwritten without confirmation."
:motion nil
:move-point nil
:type line
:repeat nil
(interactive "<R><fsh><!>")
(let* ((append-and-filename (evil-extract-append file-or-append))
(append (car append-and-filename))
(filename (cdr append-and-filename))
(bufname (buffer-file-name (buffer-base-buffer))))
(when (zerop (length filename))
(setq filename bufname))
(cond
((zerop (length filename))
(user-error "Please specify a file name for the buffer"))
;; execute command on region
((eq (aref filename 0) ?!)
(shell-command-on-region beg end (substring filename 1)))
;; with region or append, always save to file without resetting
;; modified flag
((or append (and beg end))
(write-region beg end filename append nil nil (not (or append bang))))
;; no current file
((null bufname)
(write-file filename (not bang)))
;; save current buffer to its file
((string= filename bufname)
(if (not bang) (save-buffer) (write-file filename)))
;; save to another file
(t
(write-region nil nil filename
nil (not bufname) nil
(not bang))))))