4

I want to be able to copy rich text with Ctrl-C, then paste it as plain text with a short cut key (such as Ctrl-Shift-V or whatever).

I'm running KDE and I use Klipper. It seems like there should be a way to make Klipper do this.

Right now I have a 3-step process. I invoke Klipper at the mouse position with a shortcut. Then I select the item from Klipper's contents (even if it is the same item that would already be pasted). Then I paste with Ctrl-V. I want to reduce this to a single step.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
MountainX
  • 17,168
  • 59
  • 155
  • 264
  • 1
    You'd have to bind another key to it, but you could use `xclip -o -selection clipboard | xclip -selection clipboard | xvkbd -xsendevent -text "\\Cv" 2>/dev/null`. This pastes (in plain text), pipes to a copy command, then invokes ``+`v` to paste it. – Sparhawk Oct 17 '15 at 22:01
  • Thank you for that, but it seems there should be a way to do this with klipper... – MountainX Oct 18 '15 at 01:13
  • I don't think there's a single-step way to do it with Klipper. If you look at its shortcut settings, there are only a limited amount of commands available to bind to keys. Conceivably you could configure something in "Actions", but you'd still need one keystroke to "Manually Invoke Action on Current Clipboard", and another to actually paste. I think your only single-step solution is creating a independent command yourself. – Sparhawk Oct 18 '15 at 01:18
  • Thanks again. I have it all set up and all the pieces of it seem to work except the last part -- invoking +v to paste it. I have to use my shortcut and then follow it with +v. Might I need to change the double quotes to single or drop the two backslashes? – MountainX Oct 18 '15 at 01:30
  • You'll have to install `xvkbd` (if you haven't done so already). If you need to troubleshoot further, try running `xvkbd -xsendevent -text 'foo'` from the command line, and see if `foo` is typed for you. – Sparhawk Oct 18 '15 at 01:36
  • Thanks. That did it. (I'm not sure why, but I thought installing xbindkeys was sufficient. I guess I just needed xvkbd, and not xbindkeys.) – MountainX Oct 18 '15 at 01:42

2 Answers2

4

I don't think there's a single-step way to do it with Klipper alone. If you look at its shortcut settings, there are only a limited amount of commands available to bind to keys. Conceivably you could configure something in "Actions", but you'd still need one keystroke to "Manually Invoke Action on Current Clipboard", and another to actually paste. I think your only single-step solution is creating a independent command yourself.

For example, you could install xvkbd, then bind the following to a shortcut key:

xclip -o -selection clipboard | xclip -selection clipboard | xvkbd -xsendevent -text "\\Cv" 2>/dev/null

This reads from the clipboard (in plain text), pipes it back into the clipboard, then invokes Ctrl+v to paste it.

A couple of caveats:

  • This replaces the contents of the clipboard with the "plain" version.
  • This relies on Ctrl+v being the keyboard shortcut to paste, which may not be true (e.g. in some terminal emulators).
Sparhawk
  • 19,561
  • 18
  • 86
  • 152
0

Although sparhawk has already answered the question this may help others comming to this post and it also provides a way to protect the copied/pasted text if you are dealing with creds. It is based in wayland clipboard tools.

I added a command similar to this to Plasma custom shortcuts in SystemSettings (in the example I read the secret from secrets service):

wl-copy -t "x-kde-passwordManagerHint" "$(secret-tool lookup lookup_key my_pass)" && xvkbd -xsendevent -text "$(wl-paste)"