wsl 终端中的 emacs 如何与 windows 共享剪贴板

我在 wsl 的终端中运行 emacs(终端用的是微软家的 windows terminal),现在遇到的问题是,emacs 中复制的文本内容,没有进入 windows 的系统剪贴板,如果用鼠标在 wsl 终端中拖动选择后复制,复制内容倒是可以进入 windows 系统剪贴板,但它会把前面的行号也一起复制上。有没有人解决过此问题呀?

2 个赞

你用ctrl+insert复制试试看呢?

(defun wsl-copy-region-to-clipboard (start end)
  "Copy region to Windows clipboard."
  (interactive "r")
  (call-process-region start end "clip.exe" nil 0))

(defun wsl-cut-region-to-clipboard (start end)
  (interactive "r")
  (call-process-region start end "clip.exe" nil 0)
  (kill-region start end))

(defun wsl-clipboard-to-string ()
  "Return Windows clipboard as string."
  (let ((coding-system-for-read 'dos))
(substring; remove added trailing \n
 (shell-command-to-string
  "powershell.exe -Command Get-Clipboard") 0 -1)))

(defun wsl-paste-from-clipboard (arg)
  "Insert Windows clipboard at point. With prefix ARG, also add to kill-ring"
  (interactive "P")
  (let ((clip (wsl-clipboard-to-string)))
(insert clip)
(if arg (kill-new clip))))

(define-key global-map (kbd "C-x C-y") 'wsl-paste-from-clipboard)
(define-key global-map (kbd "C-x M-w") 'wsl-copy-region-to-clipboard)
(define-key global-map (kbd "C-x C-w") 'wsl-cut-region-to-clipboard)
7 个赞

哇,原来如此,灰常灰常的感谢.

https://develop.spacemacs.org/layers/+tools/xclipboard/README.html

我用的这个

使用 xlip 包啊,完美融合。 不需要另外定制快捷键。
https://elpa.gnu.org/packages/xclip.html

1 个赞

;; ssh中emacs copy的内容放到系统剪切板 ;; mac下不需要tmux配合其他配置 ;; GitHub - spudlyo/clipetty: Manipulate the system (clip)board with (e)macs from a (tty) (use-package clipetty :ensure t :hook (after-init . global-clipetty-mode) )

tmux 中也需要配置:

emacs clipetty包需要此项配置

GitHub - spudlyo/clipetty: Manipulate the system (clip)board with (e)macs from a (tty)

set -s set-clipboard on set -ag update-environment “SSH_TTY”

1 个赞