Keyboard shortcut for pasting the primary selection
Is there a standard or conventional keyboard shortcut for pasting the primary selection?
I'd like to select some text and go to another app to paste without trashing my clipboard contents. I'd rather keep my fingers on the keyboard than move to the mouse, find the pointer, position it where I want, and middle-click.
If there's nothing conventional, or if it's application-specific and unsupported by many, is there a workaround to get this working globally? (Or at least in more applications.)
keyboard shortcut-keys clipboard
add a comment |
Is there a standard or conventional keyboard shortcut for pasting the primary selection?
I'd like to select some text and go to another app to paste without trashing my clipboard contents. I'd rather keep my fingers on the keyboard than move to the mouse, find the pointer, position it where I want, and middle-click.
If there's nothing conventional, or if it's application-specific and unsupported by many, is there a workaround to get this working globally? (Or at least in more applications.)
keyboard shortcut-keys clipboard
2
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16
add a comment |
Is there a standard or conventional keyboard shortcut for pasting the primary selection?
I'd like to select some text and go to another app to paste without trashing my clipboard contents. I'd rather keep my fingers on the keyboard than move to the mouse, find the pointer, position it where I want, and middle-click.
If there's nothing conventional, or if it's application-specific and unsupported by many, is there a workaround to get this working globally? (Or at least in more applications.)
keyboard shortcut-keys clipboard
Is there a standard or conventional keyboard shortcut for pasting the primary selection?
I'd like to select some text and go to another app to paste without trashing my clipboard contents. I'd rather keep my fingers on the keyboard than move to the mouse, find the pointer, position it where I want, and middle-click.
If there's nothing conventional, or if it's application-specific and unsupported by many, is there a workaround to get this working globally? (Or at least in more applications.)
keyboard shortcut-keys clipboard
keyboard shortcut-keys clipboard
edited Dec 27 '10 at 13:51
Stefano Palazzo♦
62.3k33183216
62.3k33183216
asked Oct 16 '10 at 18:39
Roger Pate
2
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16
add a comment |
2
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16
2
2
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16
add a comment |
7 Answers
7
active
oldest
votes
Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd
ignores the current state of your physical keyboard:
sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'
xvkbd -text
uses a few backslash sequences, so rather than dance with escaping, -file
works. xvkbd
also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors
).
I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.
Note that you need to have xsel and xvkbd packages installed:
sudo apt-get install xsel xvkbd
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
For me,sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.
– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was inxsel
).
– sup
Mar 13 '12 at 10:50
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
It looks like the second bug is inxvkbd
.xsel
works fine with "éòü" in the primary selection, butxvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)
– Sparhawk
Jan 30 '13 at 23:38
|
show 2 more comments
You can get this with the combined use of the programs
xdotool
(click to install) and
xsel
(click to install).
xdotool
can simulate typing into a window; xsel
outputs the
contents of the PRIMARY selection (by default); the following shell
one liner will do the trick:
xdotool type `xsel`
To bind this to any key using the System->Preferences->Keyboard
shortcuts menu item it is necessary to wrap it in a shell invocation:
sh -c 'xdotool type --clearmodifiers -- "`xsel`"'
Typing in xdotool
will not work with some programs; see the notes in
the xdotool documentation.
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
|
show 3 more comments
I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.
add a comment |
Calling xdotool click --clearmodifiers 2
simulates clicking middle mouse button. This works much better than using xsel (at least for me). Altough you have to position your mouse before typing...
add a comment |
Another xdotool suggestion, working in Debian Jessie 8.7 (Jan 2017):
xdotool click --delay 0 --clearmodifiers 2
- xdotool handles multi-byte strings (p.e. UTF-8), unlike xvkbd.
xdotool click
simulates an actual click, so you don't have to click yourself to paste at mouse position, as you would have if you usedxdotool type
, or xvkbd.
The only problem is that --clearmodifiers
will "press" back any modifier (Ctrl/Alt/Shift/Meta) you use after simulating the click. Even with --delay 0
(instead of 12ms), the command takes a little to execute. If you release the keys before it ends, your modifiers will be "pressed" again, and stuck there until you press and release the actual key once more.
So with this you have to be a bit "slow" (50ms?) to release your modifiers, if you're using any.
You can test this by setting up your keyboard shortcut, using it into a text editor, and then pressing a key (like a
, or an arrow). The letter should appear in lowercase. If something else happens, you are too fast and a modifier is stuck (p.e. Shift if it's in caps, Ctrl if you selected all text, Alt if you opened a menu). Press and release your modifiers again to reset them.
If you're too fast, you can use ilkerk's suggestion:
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
Then you have to release them in less than 300ms, and wait half a second for the text to appear.
Also, using xdotool type
means you insert the text as if you where typing, at the text cursor position, and not the mouse pointer. You can change it to click
if you prefer the usual middle-click behaviour.
(made this post so newcomers don't have to piece the puzzle pieces spread in the comments again)
add a comment |
I had the same issue and internet search didn't help me much.
The problem simulating click 2 is annoying as OP mentioned.
The problem with the above proposed xdotool
and xsel is when xdotool
starts "typing" you are still pressing another key. That does not always result with any output. For example if you bind it to "insert" key then xdotool
is sending keys while your finger is pressing "insert" key which causes nothing.
Below is a workaround, to bind it to a key press :
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
it is not perfect but working. now you have 0.3 seconds to finish your selection of key press (and key up).
add a comment |
I had problems with the solutions that simulate pasting the PRIMARY
selection, so instead I added a shortcut that copies the PRIMARY
selection to the CLIPBOARD
. After using my shortcut I paste the CLIPBOARD
in the usual way, with Ctrl+V
, Ctrl+Shift+V
, or Shift+Insert
, depending on the application.
The command to copy the PRIMARY
selection to the CLIPBOARD
is
sh -c 'xsel --output --primary | xsel --input --cliboard'
which I bind to Ctrl+Insert
(arbitrary choice) in the Gnome shortcut settings under System Settings -> Devices -> Keyboard
Summary of problems with other solutions: I tried the xsel | xvkbd ...
and xsel | xdotool ...
solutions, but found they didn't work very well because they simulate typing the PRIMARY
selection character by character, which is not the same as pasting it with middle click. Problems include: there's a long delay while a large selection gets inserted one character at a time; if you want to undo the "paste", you have to undo it character by character, which is slow; if you're using "dead keys" then everything gets messed up, e.g. "pasting" "e
produces ë
; the xvkdb
doesn't handle unicode characters correctly.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f7769%2fkeyboard-shortcut-for-pasting-the-primary-selection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd
ignores the current state of your physical keyboard:
sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'
xvkbd -text
uses a few backslash sequences, so rather than dance with escaping, -file
works. xvkbd
also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors
).
I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.
Note that you need to have xsel and xvkbd packages installed:
sudo apt-get install xsel xvkbd
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
For me,sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.
– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was inxsel
).
– sup
Mar 13 '12 at 10:50
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
It looks like the second bug is inxvkbd
.xsel
works fine with "éòü" in the primary selection, butxvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)
– Sparhawk
Jan 30 '13 at 23:38
|
show 2 more comments
Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd
ignores the current state of your physical keyboard:
sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'
xvkbd -text
uses a few backslash sequences, so rather than dance with escaping, -file
works. xvkbd
also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors
).
I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.
Note that you need to have xsel and xvkbd packages installed:
sudo apt-get install xsel xvkbd
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
For me,sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.
– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was inxsel
).
– sup
Mar 13 '12 at 10:50
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
It looks like the second bug is inxvkbd
.xsel
works fine with "éòü" in the primary selection, butxvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)
– Sparhawk
Jan 30 '13 at 23:38
|
show 2 more comments
Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd
ignores the current state of your physical keyboard:
sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'
xvkbd -text
uses a few backslash sequences, so rather than dance with escaping, -file
works. xvkbd
also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors
).
I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.
Note that you need to have xsel and xvkbd packages installed:
sudo apt-get install xsel xvkbd
Sending virtual keypresses doesn't work for me (see comments), but that answer inspired me to look for similar solutions. Sending a "text" event with xvkbd
ignores the current state of your physical keyboard:
sh -c 'xsel | xvkbd -xsendevent -file - 2>/dev/null'
xvkbd -text
uses a few backslash sequences, so rather than dance with escaping, -file
works. xvkbd
also outputs some warning text about modifiers, but it appears to be irrelevant to this use (but I didn't want to see it in ~/.xsession-errors
).
I bound this to a shortcut using System > Preferences > Keyboard Shortcuts.
Note that you need to have xsel and xvkbd packages installed:
sudo apt-get install xsel xvkbd
edited Apr 13 '17 at 12:24
Community♦
1
1
answered Oct 16 '10 at 21:30
Roger Pate
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
For me,sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.
– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was inxsel
).
– sup
Mar 13 '12 at 10:50
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
It looks like the second bug is inxvkbd
.xsel
works fine with "éòü" in the primary selection, butxvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)
– Sparhawk
Jan 30 '13 at 23:38
|
show 2 more comments
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
For me,sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.
– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was inxsel
).
– sup
Mar 13 '12 at 10:50
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
It looks like the second bug is inxvkbd
.xsel
works fine with "éòü" in the primary selection, butxvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)
– Sparhawk
Jan 30 '13 at 23:38
2
2
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
Holy bananas! It works! Thats awesome. Ubuntu should set this up by default.
– Eric Johnson
Jan 13 '11 at 1:01
8
8
For me,
sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.– sup
Mar 11 '12 at 11:46
For me,
sh -c 'xsel | xvkbd -file - 2>/dev/null'
works, -xsendevent had to get out to make it working.– sup
Mar 11 '12 at 11:46
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was in
xsel
).– sup
Mar 13 '12 at 10:50
By the way once more, I had to assign this command to a single key shortcut (luckily I have ThinkVantage button doing nothing on my Thinkpad - ctrl + alt + v behaved strangely and pasted only part of what was in
xsel
).– sup
Mar 13 '12 at 10:50
2
2
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
This works very well except for two problems. (1) I use a drop-down terminal (Guake) that I have set to hide on lose focus. Running this script removes focus temporarily from the terminal, causing it to hide. (2) It doesn't deal well with UTF-8 characters double-byte characters. e.g. if I select "éòü", using the script prints "éòü".
– Sparhawk
Jan 30 '13 at 23:18
2
2
It looks like the second bug is in
xvkbd
. xsel
works fine with "éòü" in the primary selection, but xvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)– Sparhawk
Jan 30 '13 at 23:38
It looks like the second bug is in
xvkbd
. xsel
works fine with "éòü" in the primary selection, but xvkbd
fails as the script above. (And also fails withxvkbd -text "éòü"
, although here it prints nothing.)– Sparhawk
Jan 30 '13 at 23:38
|
show 2 more comments
You can get this with the combined use of the programs
xdotool
(click to install) and
xsel
(click to install).
xdotool
can simulate typing into a window; xsel
outputs the
contents of the PRIMARY selection (by default); the following shell
one liner will do the trick:
xdotool type `xsel`
To bind this to any key using the System->Preferences->Keyboard
shortcuts menu item it is necessary to wrap it in a shell invocation:
sh -c 'xdotool type --clearmodifiers -- "`xsel`"'
Typing in xdotool
will not work with some programs; see the notes in
the xdotool documentation.
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
|
show 3 more comments
You can get this with the combined use of the programs
xdotool
(click to install) and
xsel
(click to install).
xdotool
can simulate typing into a window; xsel
outputs the
contents of the PRIMARY selection (by default); the following shell
one liner will do the trick:
xdotool type `xsel`
To bind this to any key using the System->Preferences->Keyboard
shortcuts menu item it is necessary to wrap it in a shell invocation:
sh -c 'xdotool type --clearmodifiers -- "`xsel`"'
Typing in xdotool
will not work with some programs; see the notes in
the xdotool documentation.
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
|
show 3 more comments
You can get this with the combined use of the programs
xdotool
(click to install) and
xsel
(click to install).
xdotool
can simulate typing into a window; xsel
outputs the
contents of the PRIMARY selection (by default); the following shell
one liner will do the trick:
xdotool type `xsel`
To bind this to any key using the System->Preferences->Keyboard
shortcuts menu item it is necessary to wrap it in a shell invocation:
sh -c 'xdotool type --clearmodifiers -- "`xsel`"'
Typing in xdotool
will not work with some programs; see the notes in
the xdotool documentation.
You can get this with the combined use of the programs
xdotool
(click to install) and
xsel
(click to install).
xdotool
can simulate typing into a window; xsel
outputs the
contents of the PRIMARY selection (by default); the following shell
one liner will do the trick:
xdotool type `xsel`
To bind this to any key using the System->Preferences->Keyboard
shortcuts menu item it is necessary to wrap it in a shell invocation:
sh -c 'xdotool type --clearmodifiers -- "`xsel`"'
Typing in xdotool
will not work with some programs; see the notes in
the xdotool documentation.
edited May 8 '13 at 16:52
Community♦
1
1
answered Oct 16 '10 at 19:01
Riccardo Murri
13.5k54449
13.5k54449
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
|
show 3 more comments
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
That won't work unless the active text box and cursor position is at that exact position, and it certainly isn't. In fact, if this counts the window manager border, that will do my "middle-click on window title" action, which is completely different.
– Roger Pate
Oct 16 '10 at 19:11
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
@Roger Thanks, corrected the text. I'm curious whether there's a better way to do this: I myself have been looking for a "paste"-key for quite some time...
– Riccardo Murri
Oct 16 '10 at 19:24
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
Well, I appreciate the effort, but this still won't work. If I wanted to worry about the mouse position, I'd just use the mouse in the first place. :)
– Roger Pate
Oct 16 '10 at 19:29
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
@Roger: Got it correct second time round: xdotool+xsel does it. (Well, at least works for me.)
– Riccardo Murri
Oct 16 '10 at 19:36
2
2
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
Needs --clearmodifiers option, otherwise there's a race condition between releasing the keyboard shortcut and xdotool executing. The xdotool in 10.04's repos isn't updated for this option, I had to download and build it myself. However, --clearmodifiers seems to strangely affect the modifiers, and I don't see how, in the end, to make xdotool work for my keyboard shortcut (though it works great for virtually typing text).
– Roger Pate
Oct 16 '10 at 20:52
|
show 3 more comments
I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.
add a comment |
I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.
add a comment |
I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.
I was looking for an answer for this very same question, and I found this answer that says that Shift+Insert is working to paste the primary selection. I works for me. Simpler.
edited Apr 13 '17 at 12:23
Community♦
1
1
answered Oct 5 '16 at 14:47
Anne
1412
1412
add a comment |
add a comment |
Calling xdotool click --clearmodifiers 2
simulates clicking middle mouse button. This works much better than using xsel (at least for me). Altough you have to position your mouse before typing...
add a comment |
Calling xdotool click --clearmodifiers 2
simulates clicking middle mouse button. This works much better than using xsel (at least for me). Altough you have to position your mouse before typing...
add a comment |
Calling xdotool click --clearmodifiers 2
simulates clicking middle mouse button. This works much better than using xsel (at least for me). Altough you have to position your mouse before typing...
Calling xdotool click --clearmodifiers 2
simulates clicking middle mouse button. This works much better than using xsel (at least for me). Altough you have to position your mouse before typing...
answered Dec 13 '13 at 17:18
Robert Jakob
211
211
add a comment |
add a comment |
Another xdotool suggestion, working in Debian Jessie 8.7 (Jan 2017):
xdotool click --delay 0 --clearmodifiers 2
- xdotool handles multi-byte strings (p.e. UTF-8), unlike xvkbd.
xdotool click
simulates an actual click, so you don't have to click yourself to paste at mouse position, as you would have if you usedxdotool type
, or xvkbd.
The only problem is that --clearmodifiers
will "press" back any modifier (Ctrl/Alt/Shift/Meta) you use after simulating the click. Even with --delay 0
(instead of 12ms), the command takes a little to execute. If you release the keys before it ends, your modifiers will be "pressed" again, and stuck there until you press and release the actual key once more.
So with this you have to be a bit "slow" (50ms?) to release your modifiers, if you're using any.
You can test this by setting up your keyboard shortcut, using it into a text editor, and then pressing a key (like a
, or an arrow). The letter should appear in lowercase. If something else happens, you are too fast and a modifier is stuck (p.e. Shift if it's in caps, Ctrl if you selected all text, Alt if you opened a menu). Press and release your modifiers again to reset them.
If you're too fast, you can use ilkerk's suggestion:
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
Then you have to release them in less than 300ms, and wait half a second for the text to appear.
Also, using xdotool type
means you insert the text as if you where typing, at the text cursor position, and not the mouse pointer. You can change it to click
if you prefer the usual middle-click behaviour.
(made this post so newcomers don't have to piece the puzzle pieces spread in the comments again)
add a comment |
Another xdotool suggestion, working in Debian Jessie 8.7 (Jan 2017):
xdotool click --delay 0 --clearmodifiers 2
- xdotool handles multi-byte strings (p.e. UTF-8), unlike xvkbd.
xdotool click
simulates an actual click, so you don't have to click yourself to paste at mouse position, as you would have if you usedxdotool type
, or xvkbd.
The only problem is that --clearmodifiers
will "press" back any modifier (Ctrl/Alt/Shift/Meta) you use after simulating the click. Even with --delay 0
(instead of 12ms), the command takes a little to execute. If you release the keys before it ends, your modifiers will be "pressed" again, and stuck there until you press and release the actual key once more.
So with this you have to be a bit "slow" (50ms?) to release your modifiers, if you're using any.
You can test this by setting up your keyboard shortcut, using it into a text editor, and then pressing a key (like a
, or an arrow). The letter should appear in lowercase. If something else happens, you are too fast and a modifier is stuck (p.e. Shift if it's in caps, Ctrl if you selected all text, Alt if you opened a menu). Press and release your modifiers again to reset them.
If you're too fast, you can use ilkerk's suggestion:
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
Then you have to release them in less than 300ms, and wait half a second for the text to appear.
Also, using xdotool type
means you insert the text as if you where typing, at the text cursor position, and not the mouse pointer. You can change it to click
if you prefer the usual middle-click behaviour.
(made this post so newcomers don't have to piece the puzzle pieces spread in the comments again)
add a comment |
Another xdotool suggestion, working in Debian Jessie 8.7 (Jan 2017):
xdotool click --delay 0 --clearmodifiers 2
- xdotool handles multi-byte strings (p.e. UTF-8), unlike xvkbd.
xdotool click
simulates an actual click, so you don't have to click yourself to paste at mouse position, as you would have if you usedxdotool type
, or xvkbd.
The only problem is that --clearmodifiers
will "press" back any modifier (Ctrl/Alt/Shift/Meta) you use after simulating the click. Even with --delay 0
(instead of 12ms), the command takes a little to execute. If you release the keys before it ends, your modifiers will be "pressed" again, and stuck there until you press and release the actual key once more.
So with this you have to be a bit "slow" (50ms?) to release your modifiers, if you're using any.
You can test this by setting up your keyboard shortcut, using it into a text editor, and then pressing a key (like a
, or an arrow). The letter should appear in lowercase. If something else happens, you are too fast and a modifier is stuck (p.e. Shift if it's in caps, Ctrl if you selected all text, Alt if you opened a menu). Press and release your modifiers again to reset them.
If you're too fast, you can use ilkerk's suggestion:
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
Then you have to release them in less than 300ms, and wait half a second for the text to appear.
Also, using xdotool type
means you insert the text as if you where typing, at the text cursor position, and not the mouse pointer. You can change it to click
if you prefer the usual middle-click behaviour.
(made this post so newcomers don't have to piece the puzzle pieces spread in the comments again)
Another xdotool suggestion, working in Debian Jessie 8.7 (Jan 2017):
xdotool click --delay 0 --clearmodifiers 2
- xdotool handles multi-byte strings (p.e. UTF-8), unlike xvkbd.
xdotool click
simulates an actual click, so you don't have to click yourself to paste at mouse position, as you would have if you usedxdotool type
, or xvkbd.
The only problem is that --clearmodifiers
will "press" back any modifier (Ctrl/Alt/Shift/Meta) you use after simulating the click. Even with --delay 0
(instead of 12ms), the command takes a little to execute. If you release the keys before it ends, your modifiers will be "pressed" again, and stuck there until you press and release the actual key once more.
So with this you have to be a bit "slow" (50ms?) to release your modifiers, if you're using any.
You can test this by setting up your keyboard shortcut, using it into a text editor, and then pressing a key (like a
, or an arrow). The letter should appear in lowercase. If something else happens, you are too fast and a modifier is stuck (p.e. Shift if it's in caps, Ctrl if you selected all text, Alt if you opened a menu). Press and release your modifiers again to reset them.
If you're too fast, you can use ilkerk's suggestion:
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
Then you have to release them in less than 300ms, and wait half a second for the text to appear.
Also, using xdotool type
means you insert the text as if you where typing, at the text cursor position, and not the mouse pointer. You can change it to click
if you prefer the usual middle-click behaviour.
(made this post so newcomers don't have to piece the puzzle pieces spread in the comments again)
edited Mar 10 '17 at 1:11
answered Mar 8 '17 at 20:43
Chema
1266
1266
add a comment |
add a comment |
I had the same issue and internet search didn't help me much.
The problem simulating click 2 is annoying as OP mentioned.
The problem with the above proposed xdotool
and xsel is when xdotool
starts "typing" you are still pressing another key. That does not always result with any output. For example if you bind it to "insert" key then xdotool
is sending keys while your finger is pressing "insert" key which causes nothing.
Below is a workaround, to bind it to a key press :
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
it is not perfect but working. now you have 0.3 seconds to finish your selection of key press (and key up).
add a comment |
I had the same issue and internet search didn't help me much.
The problem simulating click 2 is annoying as OP mentioned.
The problem with the above proposed xdotool
and xsel is when xdotool
starts "typing" you are still pressing another key. That does not always result with any output. For example if you bind it to "insert" key then xdotool
is sending keys while your finger is pressing "insert" key which causes nothing.
Below is a workaround, to bind it to a key press :
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
it is not perfect but working. now you have 0.3 seconds to finish your selection of key press (and key up).
add a comment |
I had the same issue and internet search didn't help me much.
The problem simulating click 2 is annoying as OP mentioned.
The problem with the above proposed xdotool
and xsel is when xdotool
starts "typing" you are still pressing another key. That does not always result with any output. For example if you bind it to "insert" key then xdotool
is sending keys while your finger is pressing "insert" key which causes nothing.
Below is a workaround, to bind it to a key press :
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
it is not perfect but working. now you have 0.3 seconds to finish your selection of key press (and key up).
I had the same issue and internet search didn't help me much.
The problem simulating click 2 is annoying as OP mentioned.
The problem with the above proposed xdotool
and xsel is when xdotool
starts "typing" you are still pressing another key. That does not always result with any output. For example if you bind it to "insert" key then xdotool
is sending keys while your finger is pressing "insert" key which causes nothing.
Below is a workaround, to bind it to a key press :
sh -c 'sleep 0.3 && xdotool type --clearmodifiers --delay 0 "`xsel`"'
it is not perfect but working. now you have 0.3 seconds to finish your selection of key press (and key up).
edited Feb 11 '16 at 20:20
Karl Richter
2,38183467
2,38183467
answered Feb 11 '16 at 17:04
ilkerk
1
1
add a comment |
add a comment |
I had problems with the solutions that simulate pasting the PRIMARY
selection, so instead I added a shortcut that copies the PRIMARY
selection to the CLIPBOARD
. After using my shortcut I paste the CLIPBOARD
in the usual way, with Ctrl+V
, Ctrl+Shift+V
, or Shift+Insert
, depending on the application.
The command to copy the PRIMARY
selection to the CLIPBOARD
is
sh -c 'xsel --output --primary | xsel --input --cliboard'
which I bind to Ctrl+Insert
(arbitrary choice) in the Gnome shortcut settings under System Settings -> Devices -> Keyboard
Summary of problems with other solutions: I tried the xsel | xvkbd ...
and xsel | xdotool ...
solutions, but found they didn't work very well because they simulate typing the PRIMARY
selection character by character, which is not the same as pasting it with middle click. Problems include: there's a long delay while a large selection gets inserted one character at a time; if you want to undo the "paste", you have to undo it character by character, which is slow; if you're using "dead keys" then everything gets messed up, e.g. "pasting" "e
produces ë
; the xvkdb
doesn't handle unicode characters correctly.
add a comment |
I had problems with the solutions that simulate pasting the PRIMARY
selection, so instead I added a shortcut that copies the PRIMARY
selection to the CLIPBOARD
. After using my shortcut I paste the CLIPBOARD
in the usual way, with Ctrl+V
, Ctrl+Shift+V
, or Shift+Insert
, depending on the application.
The command to copy the PRIMARY
selection to the CLIPBOARD
is
sh -c 'xsel --output --primary | xsel --input --cliboard'
which I bind to Ctrl+Insert
(arbitrary choice) in the Gnome shortcut settings under System Settings -> Devices -> Keyboard
Summary of problems with other solutions: I tried the xsel | xvkbd ...
and xsel | xdotool ...
solutions, but found they didn't work very well because they simulate typing the PRIMARY
selection character by character, which is not the same as pasting it with middle click. Problems include: there's a long delay while a large selection gets inserted one character at a time; if you want to undo the "paste", you have to undo it character by character, which is slow; if you're using "dead keys" then everything gets messed up, e.g. "pasting" "e
produces ë
; the xvkdb
doesn't handle unicode characters correctly.
add a comment |
I had problems with the solutions that simulate pasting the PRIMARY
selection, so instead I added a shortcut that copies the PRIMARY
selection to the CLIPBOARD
. After using my shortcut I paste the CLIPBOARD
in the usual way, with Ctrl+V
, Ctrl+Shift+V
, or Shift+Insert
, depending on the application.
The command to copy the PRIMARY
selection to the CLIPBOARD
is
sh -c 'xsel --output --primary | xsel --input --cliboard'
which I bind to Ctrl+Insert
(arbitrary choice) in the Gnome shortcut settings under System Settings -> Devices -> Keyboard
Summary of problems with other solutions: I tried the xsel | xvkbd ...
and xsel | xdotool ...
solutions, but found they didn't work very well because they simulate typing the PRIMARY
selection character by character, which is not the same as pasting it with middle click. Problems include: there's a long delay while a large selection gets inserted one character at a time; if you want to undo the "paste", you have to undo it character by character, which is slow; if you're using "dead keys" then everything gets messed up, e.g. "pasting" "e
produces ë
; the xvkdb
doesn't handle unicode characters correctly.
I had problems with the solutions that simulate pasting the PRIMARY
selection, so instead I added a shortcut that copies the PRIMARY
selection to the CLIPBOARD
. After using my shortcut I paste the CLIPBOARD
in the usual way, with Ctrl+V
, Ctrl+Shift+V
, or Shift+Insert
, depending on the application.
The command to copy the PRIMARY
selection to the CLIPBOARD
is
sh -c 'xsel --output --primary | xsel --input --cliboard'
which I bind to Ctrl+Insert
(arbitrary choice) in the Gnome shortcut settings under System Settings -> Devices -> Keyboard
Summary of problems with other solutions: I tried the xsel | xvkbd ...
and xsel | xdotool ...
solutions, but found they didn't work very well because they simulate typing the PRIMARY
selection character by character, which is not the same as pasting it with middle click. Problems include: there's a long delay while a large selection gets inserted one character at a time; if you want to undo the "paste", you have to undo it character by character, which is slow; if you're using "dead keys" then everything gets messed up, e.g. "pasting" "e
produces ë
; the xvkdb
doesn't handle unicode characters correctly.
answered Dec 23 at 21:36
ntc2
30329
30329
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f7769%2fkeyboard-shortcut-for-pasting-the-primary-selection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Possible same any distro: unix.stackexchange.com/questions/11889/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Apr 9 '15 at 10:13
FWIW, you can paste the primary selection from the keyboard (ie. without using mouse buttons) using shift-insert, and copy / paste the clipboard selection using ctrl-insert / ctrl-shift-insert
– Jonathan Hartley
Aug 4 '17 at 16:16