* copy-line
@ 2009-01-31 18:26 Helmut Eller
2009-01-31 19:52 ` copy-line Plamen Tanovski
` (5 more replies)
0 siblings, 6 replies; 18+ messages in thread
From: Helmut Eller @ 2009-01-31 18:26 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
is there a command (and standard key) to copy the current line? The
command should duplicate the text of the current line and move point to
the copied line. I think that vi has something like that, and
occasionally it would be quite useful.
I can write that myself but maybe Emacs has something already and I
don't know it? It's also a bit hard to find a free key :-)
Helmut.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-01-31 18:26 copy-line Helmut Eller
@ 2009-01-31 19:52 ` Plamen Tanovski
2009-02-01 1:18 ` copy-line Joe Fineman
` (4 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Plamen Tanovski @ 2009-01-31 19:52 UTC (permalink / raw)
To: help-gnu-emacs
Helmut Eller <eller.helmut@gmail.com> writes:
> is there a command (and standard key) to copy the current line? The
> command should duplicate the text of the current line and move point to
> the copied line. I think that vi has something like that, and
> occasionally it would be quite useful.
Look at extraedit.el. It offers get-current-line and may be of interest
line-comment-and-duplicate.
best regards
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-01-31 18:26 copy-line Helmut Eller
2009-01-31 19:52 ` copy-line Plamen Tanovski
@ 2009-02-01 1:18 ` Joe Fineman
2009-02-01 2:06 ` copy-line Samuel Wales
` (3 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Joe Fineman @ 2009-02-01 1:18 UTC (permalink / raw)
To: help-gnu-emacs
Helmut Eller <eller.helmut@gmail.com> writes:
> is there a command (and standard key) to copy the current line? The
> command should duplicate the text of the current line and move point
> to the copied line. I think that vi has something like that, and
> occasionally it would be quite useful.
>
> I can write that myself but maybe Emacs has something already and I
> don't know it? It's also a bit hard to find a free key :-)
I have been using the following kluge extensively for a long time. I
mainly use it in tables, but it is also useful for duplicating a line
that contains no tabs:
(defun ditto ()
"In a table, duplicate the entry above."
(interactive)
(let ((track-eol) (goal-column (current-column)))
(skip-chars-backward "^\t\n")
(setq newplace (point-marker))
(previous-line 1)
(setq oldplace (point-marker))
(skip-chars-forward "^\t\n")
(setq entry (buffer-substring oldplace (point)))
(goto-char newplace)
(skip-chars-forward "^\t\n")
(delete-region newplace (point))
(set-mark (point))
(insert entry)
)
)
--
--- Joe Fineman joe_f@verizon.net
||: It could have been worse -- it could have been me. :||
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-01-31 18:26 copy-line Helmut Eller
2009-01-31 19:52 ` copy-line Plamen Tanovski
2009-02-01 1:18 ` copy-line Joe Fineman
@ 2009-02-01 2:06 ` Samuel Wales
2009-02-01 2:09 ` copy-line Andy Stewart
` (2 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Samuel Wales @ 2009-02-01 2:06 UTC (permalink / raw)
To: Helmut Eller; +Cc: help-gnu-emacs
(defun alpha-open-line-entire (&optional arg)
"Open a line above. If there is a prefix argument of just C-u,
then repeat the line. If there are two, repeat and comment. If
there is a natural numeric argument, repeat that many lines."
(interactive "*P")
(if arg
(progn
(repeat-line (if (consp arg) 1 (prefix-numeric-value arg)))
;;put a commented line in front of the line
(when (= (car arg) 16)
(comment-region (point-at-bol) (point-at-eol))
;;this misplaces point, but cannot be fixed without
;;knowing whether ;;; or ;; or #.
(next-line)
'(back-to-indentation)))
(progn
(beginning-of-line)
;;2004-01-30 open-line just went awol, acting like yank
;;(open-line 1)
(newline 1)
(forward-line -1)
(unless (bobp)
;;(let ((indent-line-function 'alpha-indent-to-next-indentation))
(indent-according-to-mode)))))
On Sat, Jan 31, 2009 at 11:26, Helmut Eller <eller.helmut@gmail.com> wrote:
> Hello,
>
> is there a command (and standard key) to copy the current line? The
> command should duplicate the text of the current line and move point to
> the copied line. I think that vi has something like that, and
> occasionally it would be quite useful.
>
> I can write that myself but maybe Emacs has something already and I
> don't know it? It's also a bit hard to find a free key :-)
>
> Helmut.
>
--
For personal and corporate gain, myalgic encephalomyelitis denialists
are knowingly causing massive suffering and 25-years-early death by
grossly corrupting science.
http://www.meactionuk.org.uk/What_Is_ME_What_Is_CFS.htm
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-01-31 18:26 copy-line Helmut Eller
` (2 preceding siblings ...)
2009-02-01 2:06 ` copy-line Samuel Wales
@ 2009-02-01 2:09 ` Andy Stewart
[not found] ` <mailman.6387.1233454226.26697.help-gnu-emacs@gnu.org>
2009-02-01 10:13 ` copy-line Harald Hanche-Olsen
5 siblings, 0 replies; 18+ messages in thread
From: Andy Stewart @ 2009-02-01 2:09 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
Below are my code:
------------------------------> Code start <------------------------------
(defun duplicate-line-above (&optional reverse)
"Duplicate current line above."
(interactive)
(let ((origianl-column (current-column))
line-content)
(setq line-content (buffer-substring (line-beginning-position) (line-end-position)))
(beginning-of-line)
(and reverse (forward-line +1))
(newline +1)
(forward-line -1)
(insert line-content)
(goto-column origianl-column)))
(defun duplicate-line-below ()
"Duplicate current line below"
(interactive)
(duplicate-line-above t))
(defun duplicate-line-above-comment (&optional reverse)
"Duplicate current line above, and comment current line."
(interactive)
(if reverse
(duplicate-line-below)
(duplicate-line-above))
(save-excursion
(if reverse
(forward-line -1)
(forward-line +1))
(comment-or-uncomment-region+)))
(defun duplicate-line-below-comment ()
"Duplicate current line below, and comment current line."
(interactive)
(duplicate-line-above-comment t))
------------------------------> Code end <------------------------------
You can find those code at http://www.emacswiki.org/cgi-bin/emacs/lazycat-toolkit.el
Below are my keybing for those command:
------------------------------> keybinding start <------------------------------
("C-S-o" . duplicate-line-above)
("C-S-l" . duplicate-line-below)
("C-S-s-o" . duplicate-line-above-comment)
("C-S-s-l" . duplicate-line-below-comment)
------------------------------> keybinding end <------------------------------
Enjoy!
-- Andy
Helmut Eller <eller.helmut@gmail.com> writes:
> Hello,
>
> is there a command (and standard key) to copy the current line? The
> command should duplicate the text of the current line and move point to
> the copied line. I think that vi has something like that, and
> occasionally it would be quite useful.
>
> I can write that myself but maybe Emacs has something already and I
> don't know it? It's also a bit hard to find a free key :-)
>
> Helmut.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
[not found] ` <mailman.6387.1233454226.26697.help-gnu-emacs@gnu.org>
@ 2009-02-01 8:41 ` Helmut Eller
2009-02-01 10:17 ` copy-line Peter Dyballa
0 siblings, 1 reply; 18+ messages in thread
From: Helmut Eller @ 2009-02-01 8:41 UTC (permalink / raw)
To: help-gnu-emacs
Thanks to everyone who replied.
Apparently Emacs has no standard command to do that.
I'll use the code below and bind it to C-x ,
Helmut.
(defun copy-line ()
"Copy the current line."
(interactive)
(let ((col (current-column))
(beg (progn (beginning-of-line) (point)))
(end (progn (end-of-line) (point))))
(forward-line)
(save-excursion (insert (buffer-substring beg end) "\n"))
(move-to-column col)))
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-01-31 18:26 copy-line Helmut Eller
` (4 preceding siblings ...)
[not found] ` <mailman.6387.1233454226.26697.help-gnu-emacs@gnu.org>
@ 2009-02-01 10:13 ` Harald Hanche-Olsen
2009-02-01 11:45 ` copy-line Helmut Eller
5 siblings, 1 reply; 18+ messages in thread
From: Harald Hanche-Olsen @ 2009-02-01 10:13 UTC (permalink / raw)
To: help-gnu-emacs
+ Helmut Eller <eller.helmut@gmail.com>:
> is there a command (and standard key) to copy the current line? The
> command should duplicate the text of the current line and move point
> to the copied line.
Lots of suggestions here, but what is wrong with C-a C-k C-k C-y C-y?
> I think that vi has something like that
You mean yyp perhaps? The exact analogy of the above, but shorter.
Once upon a time, I thought it was cute to write elisp functions to
implement marginal time savings like the one you ask for. But in the
end, it turns out I am not using them enough to justify the cost of
writing them in the first place, and I even end up forgetting about
having such shortcuts when I could have used them.
Spend a little time on learning to use keyboard macros instead. They can
save a lot of time if you find yourself doing the same thing over and
over again.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-02-01 8:41 ` copy-line Helmut Eller
@ 2009-02-01 10:17 ` Peter Dyballa
0 siblings, 0 replies; 18+ messages in thread
From: Peter Dyballa @ 2009-02-01 10:17 UTC (permalink / raw)
To: Helmut Eller; +Cc: help-gnu-emacs
Am 01.02.2009 um 09:41 schrieb Helmut Eller:
> I'll use the code below and bind it to C-x ,
C-a C-k C-_ puts the line in the kill-ring, C-y spits it out,
anywhere ...
--
Mit friedvollen Grüßen
Pete
Be careful of reading health books, you might die of a misprint.
– Mark Twain
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-02-01 10:13 ` copy-line Harald Hanche-Olsen
@ 2009-02-01 11:45 ` Helmut Eller
2009-02-01 15:40 ` copy-line Harald Hanche-Olsen
0 siblings, 1 reply; 18+ messages in thread
From: Helmut Eller @ 2009-02-01 11:45 UTC (permalink / raw)
To: help-gnu-emacs
* Harald Hanche-Olsen [2009-02-01 11:13+0100] writes:
> Lots of suggestions here, but what is wrong with C-a C-k C-k C-y C-y?
Well, I did C-a <down> C-<spc> C-w C-y C-y before and I often get it
wrong so that it insert 2 lines (often an empty one) and I have to edit
that again.
> Spend a little time on learning to use keyboard macros instead. They can
> save a lot of time if you find yourself doing the same thing over and
> over again.
Are you saving your macros to a file? I never do that. Simply because
editing Lisp code is much easier for me than editing keyboard macros.
Helmut.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2009-02-01 11:45 ` copy-line Helmut Eller
@ 2009-02-01 15:40 ` Harald Hanche-Olsen
0 siblings, 0 replies; 18+ messages in thread
From: Harald Hanche-Olsen @ 2009-02-01 15:40 UTC (permalink / raw)
To: help-gnu-emacs
+ Helmut Eller <eller.helmut@gmail.com>:
> * Harald Hanche-Olsen [2009-02-01 11:13+0100] writes:
>
>> Spend a little time on learning to use keyboard macros instead. They can
>> save a lot of time if you find yourself doing the same thing over and
>> over again.
>
> Are you saving your macros to a file? I never do that.
No. I create them when needed, then forget them.
> Simply because editing Lisp code is much easier for me than editing
> keyboard macros.
Sure. I don't bother with editing keyboard macros either. If I make a
mistake while recording one, I make it over again from scratch. And I am
not saying you shouldn't write elisp code, nor that I don't do it
myself. But in my experience, it is often a wasted effort when dealing
with relatively simple repetitive tasks. It all depends on how often the
task crops up, and how hard it is to get it right.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
^ permalink raw reply [flat|nested] 18+ messages in thread
* copy-line
2012-07-05 19:08 copy-line (& default keychord) Enda
@ 2012-07-24 16:06 ` Enda
2012-07-24 17:44 ` copy-line Bastien
2012-07-25 18:47 ` copy-line Guido Van Hoecke
[not found] ` <mailman.5498.1343146029.855.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 18+ messages in thread
From: Enda @ 2012-07-24 16:06 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 264 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1052 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-24 16:06 ` copy-line Enda
@ 2012-07-24 17:44 ` Bastien
2012-07-25 18:47 ` copy-line Guido Van Hoecke
1 sibling, 0 replies; 18+ messages in thread
From: Bastien @ 2012-07-24 17:44 UTC (permalink / raw)
To: Enda; +Cc: help-gnu-emacs@gnu.org
Enda <enda_k2@yahoo.com> writes:
> 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?
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
[not found] ` <mailman.5498.1343146029.855.help-gnu-emacs@gnu.org>
@ 2012-07-25 12:31 ` rfflrccrd
2012-07-25 13:41 ` copy-line Dan Espen
2012-07-25 13:50 ` copy-line Raffaele Ricciardi
0 siblings, 2 replies; 18+ messages in thread
From: rfflrccrd @ 2012-07-25 12:31 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: help-gnu-emacs@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.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-25 12:31 ` copy-line rfflrccrd
@ 2012-07-25 13:41 ` Dan Espen
2012-07-25 15:02 ` copy-line Raffaele Ricciardi
2012-07-25 13:50 ` copy-line Raffaele Ricciardi
1 sibling, 1 reply; 18+ messages in thread
From: Dan Espen @ 2012-07-25 13:41 UTC (permalink / raw)
To: help-gnu-emacs
rfflrccrd@gmail.com writes:
> 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.
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-25 12:31 ` copy-line rfflrccrd
2012-07-25 13:41 ` copy-line Dan Espen
@ 2012-07-25 13:50 ` Raffaele Ricciardi
1 sibling, 0 replies; 18+ messages in thread
From: Raffaele Ricciardi @ 2012-07-25 13:50 UTC (permalink / raw)
To: help-gnu-emacs
On 07/25/2012 01:31 PM, rfflrccrd@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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-25 13:41 ` copy-line Dan Espen
@ 2012-07-25 15:02 ` Raffaele Ricciardi
2012-07-25 15:06 ` copy-line Raffaele Ricciardi
0 siblings, 1 reply; 18+ messages in thread
From: Raffaele Ricciardi @ 2012-07-25 15:02 UTC (permalink / raw)
To: help-gnu-emacs
's requirement is that for its was that you shouldn't ha.On 07/25/2012
02:41 PM, Dan Espen wrote:> rfflrccrd@gmail.com writes:
>
>> 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.
>
> 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
>
>
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 :-)
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-25 15:02 ` copy-line Raffaele Ricciardi
@ 2012-07-25 15:06 ` Raffaele Ricciardi
0 siblings, 0 replies; 18+ messages in thread
From: Raffaele Ricciardi @ 2012-07-25 15:06 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: copy-line
2012-07-24 16:06 ` copy-line Enda
2012-07-24 17:44 ` copy-line Bastien
@ 2012-07-25 18:47 ` Guido Van Hoecke
1 sibling, 0 replies; 18+ messages in thread
From: Guido Van Hoecke @ 2012-07-25 18:47 UTC (permalink / raw)
To: Enda; +Cc: help-gnu-emacs@gnu.org
On 24 July 2012 18:06, Enda <enda_k2@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!
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2012-07-25 18:47 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-31 18:26 copy-line Helmut Eller
2009-01-31 19:52 ` copy-line Plamen Tanovski
2009-02-01 1:18 ` copy-line Joe Fineman
2009-02-01 2:06 ` copy-line Samuel Wales
2009-02-01 2:09 ` copy-line Andy Stewart
[not found] ` <mailman.6387.1233454226.26697.help-gnu-emacs@gnu.org>
2009-02-01 8:41 ` copy-line Helmut Eller
2009-02-01 10:17 ` copy-line Peter Dyballa
2009-02-01 10:13 ` copy-line Harald Hanche-Olsen
2009-02-01 11:45 ` copy-line Helmut Eller
2009-02-01 15:40 ` copy-line Harald Hanche-Olsen
-- strict thread matches above, loose matches on Subject: below --
2012-07-05 19:08 copy-line (& default keychord) Enda
2012-07-24 16:06 ` copy-line Enda
2012-07-24 17:44 ` copy-line Bastien
2012-07-25 18:47 ` copy-line Guido Van Hoecke
[not found] ` <mailman.5498.1343146029.855.help-gnu-emacs@gnu.org>
2012-07-25 12:31 ` copy-line rfflrccrd
2012-07-25 13:41 ` copy-line Dan Espen
2012-07-25 15:02 ` copy-line Raffaele Ricciardi
2012-07-25 15:06 ` copy-line Raffaele Ricciardi
2012-07-25 13:50 ` copy-line Raffaele Ricciardi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).