在emacs中,如何快捷复制当前行,或者复制当前段落(直到前后空行)?
可以编写elisp函数,绑定的快捷键来使用,非常方便。
在linux中选中即复制,所以只需要挪动光标到开头,set mark,挪动光标到末尾。代码如下:
(defun copyline ()
"Copy current line."
(interactive)
(progn
(deactivate-mark)
(goto-char (line-beginning-position))
(set-mark-command nil)
(goto-char (line-end-position))
(message "current line is copied"))
)
复制段落的方法与复制行类似,只是要往前和往后找到空行。
(defun copyblock ()
"Copy current block."
(interactive)
(progn
(deactivate-mark)
;; move cursor to the begin the block
(goto-char (line-beginning-position))
(while (eq (string-blank-p (string-trim (thing-at-point 'line t))) nil)
(previous-line))
(next-line)
;; set mark
(set-mark-command nil)
;; move cursor to the end of the block
(while (eq (string-blank-p (string-trim (thing-at-point 'line t))) nil)
(next-line))
(message "current block is copied")
)
)
绑定快捷键到f5、f6。
(global-set-key [f18] 'copyline)
(global-set-key [f20] 'copyblock)
定位光标到行内或者段内任意地方,按一下f5或者f6,就可以去其它地方鼠标中键粘贴了。