How can I configure Emacs in the Evil mode to delete an empty line (
d d) without copying it but still copy it when deleting a non-empty line?
You can try this.
(evil-define-operator evil-delete-without-register-if-whitespace (beg end type reg yank-handler) (interactive "<R><y>") (let ((text (replace-regexp-in-string "\n" "" (filter-buffer-substring beg end)))) (if (string-match-p "^\\s-*$" text) (evil-delete beg end type ?_) (evil-delete beg end type reg yank-handler))))
Followed by rebinding
d with it:
(define-key evil-normal-state-map "d" #'evil-delete-without-register-if-whitespace)
I found this looking at this emacs configuration.
What you're asking for does not require knowledge of spacemacs. It involves evil, a package that is included in spacemacs.
evil is an operator. This defines a new operator to replace the default one; the main difference being that it checks to see if what's being added to the register is whitespace. If it is it adds nothing, otherwise it adds it to the register.
To learn more about evil check out noctuid's evil guide.
Note: that this is not strictly what you asked for because you spoke of not adding empty lines to the register while this doesn't add whitespace in general to the register (even if not a full empty line). But I suspect you'd actually find this more useful.