How do I duplicate a whole line in Emacs?

前端 未结 30 1066
时光取名叫无心
时光取名叫无心 2020-12-04 05:20

I saw this same question for VIM and it has been something that I myself wanted to know how to do for Emacs. In ReSharper I use CTRL-D for this action. What is the least num

30条回答
  •  粉色の甜心
    2020-12-04 05:37

    When called interactively with no active region, COPY (M-w) a single line instead :

    (defadvice kill-ring-save (before slick-copy activate compile)
      "When called interactively with no active region, COPY a single line instead."
      (interactive
       (if mark-active (list (region-beginning) (region-end))
         (message "Copied line")
         (list (line-beginning-position)
               (line-beginning-position 2)))))
    

    When called interactively with no active region, KILL (C-w) a single line instead.

    (defadvice kill-region (before slick-cut activate compile)
      "When called interactively with no active region, KILL a single line instead."
      (interactive
       (if mark-active (list (region-beginning) (region-end))
         (message "Killed line")
         (list (line-beginning-position)
               (line-beginning-position 2)))))
    

    Also, on a related note:

    (defun move-line-up ()
      "Move up the current line."
      (interactive)
      (transpose-lines 1)
      (forward-line -2)
      (indent-according-to-mode))
    
    (defun move-line-down ()
      "Move down the current line."
      (interactive)
      (forward-line 1)
      (transpose-lines 1)
      (forward-line -1)
      (indent-according-to-mode))
    
    (global-set-key [(meta shift up)]  'move-line-up)
    (global-set-key [(meta shift down)]  'move-line-down)
    

提交回复
热议问题