Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete the current line in Emacs?

Tags:

emacs

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.

like image 638
Manoj Govindan Avatar asked Oct 18 '10 11:10

Manoj Govindan


People also ask

What is the command to delete and cut the current line in Emacs?

The simplest kill command is C-k . If given at the beginning of a line, it kills all the text on the line, leaving it blank. When used on a blank line, it kills the whole line including its newline. To kill an entire non-blank line, go to the beginning and type C-k twice.

How do you delete text in Emacs?

Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character.

How do I select and delete text in Emacs?

Delete Selection mode lets you treat an Emacs region much like a typical text selection outside of Emacs: You can replace the active region just by typing text, and you can delete the selected text just by hitting the Backspace key ( 'DEL' ).


1 Answers

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. 
like image 151
unutbu Avatar answered Sep 29 '22 01:09

unutbu