Skip to content

Instantly share code, notes, and snippets.

@szobov
Created March 25, 2018 16:27
Show Gist options
  • Save szobov/70890efabf895a8ce7f77c4cee7ec9b6 to your computer and use it in GitHub Desktop.
Save szobov/70890efabf895a8ce7f77c4cee7ec9b6 to your computer and use it in GitHub Desktop.
Copy/paste to xclip using emacs -nw
(defun copy-to-clipboard ()
"Copies selection to x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "xsel --clipboard --input")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(defun paste-from-clipboard ()
"Pastes from x-clipboard."
(interactive)
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "xsel --clipboard --output"))
)
)
(evil-leader/set-key "o y" 'copy-to-clipboard)
(evil-leader/set-key "o p" 'paste-from-clipboard)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment