How can I delete the current line in Emacs?

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

    C-a # Go to beginning of line
    C-k # Kill line from current point
    

    There is also

    C-S-backspace   # Ctrl-Shift-Backspace
    

    which invokes M-x kill-whole-line.

    If you'd like to set a different global key binding, you'd put this in ~/.emacs:

    (global-set-key "\C-cd" 'kill-whole-line)     # Sets `C-c d` to `M-x kill-whole-line`
    

    If you want to delete a number of whole lines, you can prefix the command with a number:

    C-u 5 C-S-backspace    # deletes 5 whole lines
    M-5 C-S-backspace      # deletes 5 whole lines
    
    C-u C-S-backspace      # delete 4 whole lines. C-u without a number defaults to 4
    
    C-u -5 C-S-backspace   # deletes previous 5 whole lines
    M--5 C-S-backspace     # deletes previous 5 whole lines
    

    Sometimes I also find C-x z helpful:

    C-S-backspace         # delete 1 whole line
    C-x z                 # repeat last command
    z                     # repeat last command again. 
                          # Press z as many times as you wish. 
                          # Any other key acts normally, and ends the repeat command.
    

提交回复
热议问题