Emacs终端下的复制、粘贴

在终端中使用-nw打开emacs,剪切板命令如clipboard-kill-region、clipboard-kill-ring-save、clipboard-yank会失效,下面是从网络上找到的解决办法,在此感谢各位大神。

//转自:http://vancel1.info/copy-paste-with-emacs-in-terminal/

//最终来源:http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/

在终端里运行 emacs (emacs -nw) 做复制粘贴挺麻烦的,鼠标选中复制,鼠标中键粘贴,多行复制时还会连行号也包括进去。


下面设置是在终端里运行 emacs 执行复制、粘贴时调用 xsel ,然后你就可以将 emacs 里的内容复制(M-w)到其他外部程序,或者从外部粘贴文字(C-y)到 emacs 内。

安装 xsel
sudo aptitude install xsel

关于xsel: command-line tool to access X clipboard and selection buffers

emacs 的配置
;; 支持emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)

;; use xsel to copy/paste in emacs-nox
(unless window-system
(when (getenv "DISPLAY")
(defun xsel-cut-function (text &optional push)
(with-temp-buffer
(insert text)
(call-process-region (point-min) (point-max) "xsel" nil 0 nil "--clipboard" "--input")))
(defun xsel-paste-function()
(let ((xsel-output (shell-command-to-string "xsel --clipboard --output")))
(unless (string= (car kill-ring) xsel-output)
xsel-output )))
(setq interprogram-cut-function 'xsel-cut-function)
(setq interprogram-paste-function 'xsel-paste-function)
))

参考:http://hugoheden.wordpress.com/2009/03/08/copypaste-with-emacs-in-terminal/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值