How can I delete the current line in Emacs?

后端 未结 5 1014
别那么骄傲
别那么骄傲 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

    Another method to delete the line without placing it into the kill ring:

    (defun delete-current-line ()
      "Deletes the current line"
      (interactive)
      (delete-region
       (line-beginning-position)
       (line-end-position)))
    

    This will leave the point at the beginning of a blank line. To get rid of this also, you may wish to add something like (delete-blank-lines) to the end of the function, as in this example, which is perhaps a little less intuitive:

    (defun delete-current-line ()
     "Deletes the current line"
     (interactive)
     (forward-line 0)
     (delete-char (- (line-end-position) (point)))
     (delete-blank-lines))
    

提交回复
热议问题