tags:

views:

277

answers:

6

I run the following command in Emacs unsuccessfully

C-u

How can you clear the beginning of a line in Emacs?

+7  A: 

You can set the mark, go to the beginning, kill till mark:

C-Spc C-a C-w
Svante
@Svante: Thank you for your answer!
Masi
`C-0 C-k` is less typing http://stackoverflow.com/questions/818425/unable-to-clear-a-beginning-of-a-line-by-c-u-in-emacs/1580519#1580519
J.F. Sebastian
+5  A: 

C-u works in Bash "Emacs Mode", but not actually in Emacs. Here's what I usually do:

C-a C-k

But this is really only good if you want to kill the whole line. Svante's advice will clear from the beginning of the line to where your cursor was, as you asked for.

Naaff
A: 

I don't know, where you read about C-u, but it is bound to the universal argument in Emacs.

If you want to kill the whole line, call kill-whole-line which is bound C-S-backspace. No matter at what column is the cursor, it will kill the whole line from beginning to end.

Török Gábor
Do you mean Ctrl-Shift-backspace? It does not work for me.
Masi
Yes. Maybe your terminal does not support that sequence but you can always type `M-x kill-whole-line` or set your own shortcut with `(global-set-key [C-S-backspace] 'kill-whole-line)`.
Török Gábor
A: 

I have a small function bound to a key-chord:

(defun kill-start-of-line ()
  "kill from point to start of line"
  (interactive)
  (kill-line 0))

(define-key global-map "\M-#" 'kill-start-of-line)

M-# is usually Alt-Shift-3, not a new DotNet language

I'm sure I saw this somewhere else, but didn't save the original reference.

Michael Paulukonis
+1  A: 

You can also accomplish this by using a prefix arg for kill-ine (usually C-k). From the Emacs help (C-h k C-k):

With zero argument, kills the text before point on the current line.

So, you can do

C-u 0 C-k

or even better

C-0 C-k
Ryan E
+1: for <kbd>C-0 C-k</kbd>
J.F. Sebastian
A: 

Try this:

M-0 C-k 

Delete from beginning of line to point

Ray Vega