Emacs: what is the shortcut key to clear buffer?

后端 未结 7 1755
别跟我提以往
别跟我提以往 2021-01-30 12:45

Like, Control-A (select all) followed by delete?

相关标签:
7条回答
  • 2021-01-30 12:57

    Go to the begin of the buffer, go to the end (both set the mark), then cut:

    M-< M-> C-w
    
    0 讨论(0)
  • 2021-01-30 12:59

    C-x h + del key clears the buffer

    Note: This requires transient-mark-mode to be enabled (which it is by default).

    0 讨论(0)
  • 2021-01-30 13:01

    Old folks might like to call it hk rather than clear-buffer-permanently, and assign it to the nostalgic key sequence like so:

    (define-key esc-map "\^[hk" 'hk)
    

    That's the pre-Gnu TECO EMACS command to clear the buffer (ESC ESC wHole Kill).

    0 讨论(0)
  • 2021-01-30 13:11

    These macros build on the answers given above. To start using them paste them into your .emacs then restart emacs or (while in the .emacs buffer) type M-x eval-buffer.

    (defun clear-buffer ()
      "clear whole buffer add contents to the kill ring"
      (interactive)
      (kill-region (point-min) (point-max))
      )
    
    (defun clear-buffer-permenantly ()
      "clear whole buffer, contents is not added to the kill ring"
      (interactive)
      (delete-region (point-min) (point-max))
      )
    
    0 讨论(0)
  • 2021-01-30 13:12

    There is no shortcut, but you can define one... Follow this link to get a macro for clearing a buffer.

    0 讨论(0)
  • 2021-01-30 13:21

    Select all in Emacs is:

    C-x h
    

    (technically, that's mark-whole-buffer) and kill-region (to kill the marked region, which is now the entire buffer) is:

    C-w
    

    If you want to delete the region without copying it to the kill-ring, you can use

    M-x delete-region
    

    instead. If you do this alot, you'll want to bind delete-region to a key/key combo.

    0 讨论(0)
提交回复
热议问题