How can I delete the current line in Emacs?

后端 未结 5 1013
别那么骄傲
别那么骄傲 2021-01-29 18:42

What is the emacs equivalent of vi\'s dd? I want to delete the current line. Tried CTRL + k but it only deletes from current position.

5条回答
  •  执念已碎
    2021-01-29 19:13

    Rather than having separate key to delete line, or having to invoke prefix-argument. You can use crux-smart-kill-line which will "kill to the end of the line and kill whole line on the next call". But if you prefer delete instead of kill, you can use the code below.

    For point-to-string operation (kill/delete) I recommend to use zop-to-char

    (defun aza-delete-line ()
      "Delete from current position to end of line without pushing to `kill-ring'."
      (interactive)
      (delete-region (point) (line-end-position)))
    
    (defun aza-delete-whole-line ()
      "Delete whole line without pushing to kill-ring."
      (interactive)
      (delete-region (line-beginning-position) (line-end-position)))
    
    (defun crux-smart-delete-line ()
      "Kill to the end of the line and kill whole line on the next call."
      (interactive)
      (let ((orig-point (point)))
        (move-end-of-line 1)
        (if (= orig-point (point))
            (aza-delete-whole-line)
          (goto-char orig-point)
          (aza-delete-line))))
    

    source

提交回复
热议问题