很多时候,我发现自己需要从任何地方粘贴一条路径到emacs的迷你缓冲区。要快速清除迷你缓冲区,我导航到开头并执行C-k(终止线)。
这有效地覆盖了我在系统剪贴板中使用我在迷你缓冲区中杀死的临时路径的任何路径。用M-y导航杀伤环不会带来我在系统剪贴板中的路径。
有没有办法删除当前行而不杀死它(即删除它并将其添加到kill ring)?
到目前为止,我正在标记该行并按下删除,其中delete-selection-mote处于活动状态。我想要一个类似于C-k的一键解决方案。
答案 0 :(得分:8)
从Emacs 23.2开始,您可以将save-interprogram-paste-before-kill
设置为非零值(帽子提示Tyler),将剪贴板选项复制到kill ring上,以便通过获取Cy My :
(setq save-interprogram-paste-before-kill t)
如果您使用的是较旧的Emacs,则以下建议具有相同的功能:
(defadvice kill-new (before kill-new-push-xselection-on-kill-ring activate)
"Before putting new kill onto the kill-ring, add the clipboard/external selection to the kill ring"
(let ((have-paste (and interprogram-paste-function
(funcall interprogram-paste-function))))
(when have-paste (push have-paste kill-ring))))
并且,你可以做这样的事情(可怕的键绑定,自定义以适应)从前进点删除该行:
(define-key minibuffer-local-map (kbd "C-S-d") 'delete-line)
(defun delete-line (&optional arg)
(interactive "P")
;; taken from kill-line
(delete-region (point)
;; It is better to move point to the other end of the kill
;; before killing. That way, in a read-only buffer, point
;; moves across the text that is copied to the kill ring.
;; The choice has no effect on undo now that undo records
;; the value of point from before the command was run.
(progn
(if arg
(forward-visible-line (prefix-numeric-value arg))
(if (eobp)
(signal 'end-of-buffer nil))
(let ((end
(save-excursion
(end-of-visible-line) (point))))
(if (or (save-excursion
;; If trailing whitespace is visible,
;; don't treat it as nothing.
(unless show-trailing-whitespace
(skip-chars-forward " \t" end))
(= (point) end))
(and kill-whole-line (bolp)))
(forward-visible-line 1)
(goto-char end))))
(point))))
答案 1 :(得分:4)
从Emacs 23.2开始,可以使用save-interprogram-paste-before-kill
来解决此问题。如果将此变量设置为t
,则剪贴板中的内容会添加到kill-ring中,并且不会被您的下一次kill杀掉。
文档:
在替换它们之前,将剪贴板字符串保存到kill ring中。 当一个人选择另一个程序中的东西将其粘贴到Emacs中时, 但在实际粘贴它之前杀死了Emacs中的东西, 除非这个变量是非零的,否则这个选择就消失了 在这种情况下,其他程序的选择保存在`kill-ring'中 在Emacs杀死之前,仍然可以使用C-y M-y粘贴它。
答案 2 :(得分:1)
从Xahlee's page开始,它会显示几个烦人的命令。
(defun my-delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times.
This command does not push erased text to kill-ring."
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))
(defun my-backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument, do this that many times.
This command does not push erased text to kill-ring."
(interactive "p")
(my-delete-word (- arg)))
(defun my-delete-line ()
"Delete text from current position to end of line char."
(interactive)
(delete-region
(point)
(save-excursion (move-end-of-line 1) (point)))
(delete-char 1)
)
(defun my-delete-line-backward ()
"Delete text between the beginning of the line to the cursor position."
(interactive)
(let (x1 x2)
(setq x1 (point))
(move-beginning-of-line 1)
(setq x2 (point))
(delete-region x1 x2)))
; Here's the code to bind them with emacs's default shortcut keys:
(global-set-key (kbd "M-d") 'my-delete-word)
(global-set-key (kbd "<M-backspace>") 'my-backward-delete-word)
(global-set-key (kbd "C-k") 'my-delete-line)
(global-set-key (kbd "C-S-k") 'my-delete-line-backward)
答案 3 :(得分:0)
没有。
我们已经描述了基本的删除命令C-d (delete-char)和(delete-backward-char)。见擦除。
其他删除命令是仅删除空格的命令 字符:空格,制表符和换行符。 M- \(删除 - 水平空间) 删除点前后的所有空格和制表符。同 前缀参数,这只删除之前的空格和制表符 点。 M-(只有一个空间)同样做,但留下一个 无论存在多少空格,都可以一点一点地进行 以前(即使之前没有)。使用数字参数 n,它在点之后留下n个空格。
答案 4 :(得分:0)
如下:
(defun del-line (p1)
(interactive "d")
(move-end-of-line 1)
(when (eq p1 (point)) ; special case when p1 is already at the end of the line
(forward-line))
(delete-region p1 (point)))
行为应与C-k
类似,但不会影响系统剪贴板或杀死响铃。
ETA:我更仔细地阅读了Trey的解决方案,看起来这只是他解决方案的一个简单案例。它适用于我的(非常!)有限测试,但可能在一些特殊情况下失败,因为更复杂的终止代码可以正常工作。
答案 5 :(得分:0)
找到答案。
;; Ctrl-K with no kill (defun delete-line-no-kill () (interactive) (delete-region (point) (save-excursion (move-end-of-line 1) (point))) (delete-char 1) ) (global-set-key (kbd "C-k") 'delete-line-no-kill)