Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

copy-line

15 views
Skip to first unread message

Enda

unread,
Jul 24, 2012, 12:06:55 PM7/24/12
to help-gn...@gnu.org
Usedn't there be a copy-line in Emacs (which would copy the line). In Vi, copying a line is yy, what is the shortest way of copying a line in Emacs (without writing a lisp function in .emacs)? Should there be a default keystroke for copying a line?


- Enda


Bastien

unread,
Jul 24, 2012, 1:44:57 PM7/24/12
to Enda, help-gn...@gnu.org
What about one of these two?

(defun kill-line-save (&optional arg)
"Save the rest of the line as if killed, but don't kill it."
(interactive "P")
(let ((buffer-read-only t))
(kill-line arg)
(message "Line(s) copied to the kill ring")))

(defun copy-line (&optional arg)
"Copy the current line."
(interactive "P")
(copy-region-as-kill
(point-at-bol)
(+ (if kill-whole-line 1 0) (point-at-eol arg))))

--
Bastien

rffl...@gmail.com

unread,
Jul 25, 2012, 8:31:13 AM7/25/12
to help-gn...@gnu.org, Enda
Comparing Vi/Vim to other editors is not fair ;-)

Vanilla Emacs has no way to copy text that has not been marked. Thus, to copy a line, you have to mark it first. The complete sequence is:

C-a C-Space C-e M-w

In alternative, you can kill a line and yank it back at once:

C-S-Backspace C-k

Unlike Vi, the line will be copied/killed without its new line. I don't know whether such behaviour is customizable.

Cheers.

Raffaele Ricciardi

unread,
Jul 25, 2012, 9:50:44 AM7/25/12
to
On 07/25/2012 01:31 PM, rffl...@gmail.com wrote:
> In alternative, you can kill a line and yank it back at once:
>
> C-S-Backspace C-k

Errata corrige:

C-S-Backspace C-k C-y

Dan Espen

unread,
Jul 25, 2012, 9:41:15 AM7/25/12
to
It certainly is customizable:

(define-key global-map [(kp-add)] '(lambda () (interactive)
(beginning-of-line)
(if (eobp) (error "End of buffer"))
(let ((beg (point)))
(forward-line 1)
(kill-region beg (point))))); KeyPad + Key

Kill a line, yank it back:

C-KP+ C-y


--
Dan Espen

Raffaele Ricciardi

unread,
Jul 25, 2012, 11:02:11 AM7/25/12
to
's requirement is that for its was that you shouldn't ha.On 07/25/2012
I meant: I don't know whether it is customizable via Customize, as the
original poster asked for its .emacs to be left untouched. Thank you
for the tip, though :-)

Raffaele Ricciardi

unread,
Jul 25, 2012, 11:06:59 AM7/25/12
to
there is nothing to be customizedOn 07/25/2012 04:02 PM, Raffaele
Ricciardi wrote:> I meant: I don't know whether it is customizable via
Customize, as the
> original poster asked for its .emacs to be left untouched. Thank you
> for the tip, though :-)

Well, no customization is needed: to copy the whole line, including the
newline:

C-a C-SPC C-n M-w

Cheers.

rffl...@gmail.com

unread,
Jul 25, 2012, 8:31:13 AM7/25/12
to gnu.ema...@googlegroups.com, help-gn...@gnu.org, Enda
Comparing Vi/Vim to other editors is not fair ;-)

Vanilla Emacs has no way to copy text that has not been marked. Thus, to copy a line, you have to mark it first. The complete sequence is:

C-a C-Space C-e M-w

In alternative, you can kill a line and yank it back at once:

C-S-Backspace C-k

Andreas Röhler

unread,
Jul 25, 2012, 2:01:04 PM7/25/12
to help-gn...@gnu.org
Am 05.07.2012 21:08, schrieb Enda:
> What happened to copy-line in Emacs (which would copy the line). In Vi, copying a line is yy, what is the shortest way of copying a line in Emacs (without writing a lisp function in .emacs)? Should there be a default keychord for copying a line?
>
>
> Best wishes,
>
> Enda
>

you may try

https://launchpad.net/s-x-emacs-werkstatt/trunk/1.3/+download/S-X-Emacs-Werkstatt-1.3.tar.gz

it comes with ar-line-atpt, which should do what you want.

Also it delivers some hundred related commands, reducing the need for customizations/creations somehow

Andreas

Guido Van Hoecke

unread,
Jul 25, 2012, 2:47:22 PM7/25/12
to Enda, help-gn...@gnu.org
On 24 July 2012 18:06, Enda <end...@yahoo.com> wrote:
> Usedn't there be a copy-line in Emacs (which would copy the line). In Vi,
> copying a line is yy, what is the shortest way of copying a line in Emacs
> (without writing a lisp function in .emacs)? Should there be a default
> keystroke for copying a line?
>

You may want to look at
http://www.northbound-train.com/emacs/whole-line-or-region.el

Copies or kills with one keystroke, the default one :)

I found this via http://emacswiki.org/emacs/CopyingWholeLines
where you can find other suggestions.

I prefer the whole-line-or-region apprach.

HTH,


Guido

--
Good government never depends upon laws, but upon the personal qualities of
those who govern. The machinery of government is always subordinate to the
will of those who administer that machinery. The most important element of
government, therefore, is the method of choosing leaders.
-- Frank Herbert, "Children of Dune"

http://vanhoecke.org ... and go2 places!

0 new messages