Why does Ctrl + V not paste in Bash (Linux shell)?

196

72

When I copy something to the clipboard and press Ctrl + V in Bash, nothing happens; However, right clicking and selecting Paste does the job.

Why? Is there any reasonable issue (I'm sure there is) behind this behavior in Linux?

Yasser Zamani

Posted 2012-05-07T07:44:30.483

Reputation: 2 327

Windows has an option to allow Ctrl for copy and paste. I've noticed that Powershell seems to allow it it, at least in some modes that I've tried. – jpierson – 2015-08-29T11:37:00.613

funny note: http://superuser.com/questions/675619/why-doesnt-windows-command-prompt-still-support-ctrl-v (essentially the same question as this, but about Win) was closed as "primiarily opinion-based"...

– None – 2016-01-02T18:53:27.173

1@LưuVĩnhPhúc: Actually in Windows 10 it finally does. – user1686 – 2016-05-03T04:45:51.463

Use ^k from the start of the line to copy and ^y to paste. Similar commands for emacs. – Owl – 2016-08-01T15:25:20.090

@BenRacicot which keyboard doesn't have insert key? – phuclv – 2016-11-26T10:18:38.883

2JFTR, Ctrl-Shirt-V won't work on "older" terminal emulators such as rxvt. Another case in point is that Shirt-Insert inserts the contents of the so-called "PRIMARY" selection (the currently-active selection in another GUI application) while Ctrl-v most of the time expected to paste the content of the so-called "CLIPBOARD" selection buffer (what most people call "the clipboard" actually). – kostix – 2018-08-07T16:54:17.370

25Shift-Insert also works – bonyiii – 2012-05-07T10:57:46.440

34I prefer Ctrl-Shift-V, personally. – amalloy – 2012-05-07T18:46:50.017

3You can also use Shift + Insert in most shell environments. – Fabian – 2012-05-08T09:17:27.757

In bash itself, I prefer selecting desired text and then pressing middle click. From outside, I prefer CTRL-C then Shift-Insert in bash. – Yasser Zamani – 2012-05-08T17:55:02.710

4What if you won't have an Insert key? – Ben Racicot – 2013-10-01T23:46:21.127

1@BenRacicot, Ctrl-Shift-V also works. – Yasser Zamani – 2014-01-21T11:13:59.593

1Ctrl-Shift-V is not pasting in my clipboard, that's why I asked. – Ben Racicot – 2014-01-21T17:29:22.487

3it doesn't work in windows' command prompt too – phuclv – 2014-05-26T13:30:04.007

Answers

364

In the days of physical terminals, session-wide clipboards did not exist, only few programs supported internal copy/paste – often under the name of "buffers" or "kill rings" – and used various different keystrokes. For example, the bash shell uses CtrlK or CtrlU to "kill" (cut), CtrlY to "yank" (paste); this comes from the emacs editor.

CtrlC almost everywhere in Unix was the "interrupt" key, used to cancel the current program or operation. The CtrlV key often meant "verbatim insert" – that is, insert the following character literally without performing any associated action. For example, a normal Esc switches to command mode in the vi editor, but CtrlV, Esc will insert the ESC character into the document.

The use of CtrlC to copy and CtrlV to paste from session-wide clipboard was introduced by Mac OS in 1983 and Microsoft Windows 3.x in 1990. (Earlier Windows versions (1.x and 2.x), as well as IBM OS/2, only supported the IBM CUA keys CtrlIns to copy and ShiftIns to paste; these shortcuts remain supported by all Windows versions.)

When GUIs with clipboard support finally reached Unix, the Ctrl keypresses were already in use by many terminal programs. In addition, the X graphical interface had somewhat different mechanisms: "selections" and "cut buffers". Even now you can select text in one program and insert it using the middle mouse button, without any explicit copy action.

In short, by the time Xterm and GNOME Terminal were written (I'm guessing you use the latter), CtrlV already had a completely different meaning for many years and could not be changed. In addition, an alternative method of copying text – the "selection" – was already present in X11, so explicit copy/paste action was probably considered not as important as it would be in Windows. This means that different keyboard shortcuts had to be selected – for example, most modern terminal programs, like GNOME Terminal, use CtrlShiftC and CtrlShiftV. (If you use Xterm, the same shortcuts can be added manually using the XTerm*vt100*translations Xresource. Rxvt does not have such an option.)

(Most X11 toolkits also support the CUA "copy" and "paste" keys, which do not conflict with terminal programs. Unfortunately, the implementations are rather inconsistent – CtrlIns copies to the "clipboard" in most programs (GTK, Qt4, but ignored by Xaw); however, ShiftIns pastes from the "primary selection" in most GTK and Qt4 programs, but from "clipboard" in Firefox, and from the now-obsolete cut-buffers in the now-obsolete Xaw.)


All that said, some terminals or consoles (in particular, the Windows 10 console) do support these keys. As the Windows console always had a separate "mark/select" mode, CtrlC now also has two meanings based on context – in regular mode it sends an interrupt, in select mode it copies to clipboard (just like Enter used to).

Meanwhile, Windows command-line tools never really used CtrlV for anything, so it was bound to "paste" without disturbing much anything. Doing the same on Unix-like terminals however would be more problematic.

user1686

Posted 2012-05-07T07:44:30.483

Reputation: 283 655

Soooo - why don't these projects just change these key combo's to keep up with the times and the mass of users? I'm sure there are more users that expect the ctrl+c and ctrl+v as copy and paste. I am used to using ctrl+c to stop processes, but i'm sure id get over it quickly if it is changed. – Nay – 2016-02-19T07:48:13.553

@grawity I just upvoted this excellent answer (and over the past couple of days, other related answers by you). In your first sentence, did you mean registers when you wrote buffers? A buffer (for both Vi and Emacs), is how the file contents are referred to when loaded into memory. – Anthony Geoghegan – 2016-05-02T19:05:54.770

I tried to use you instruction for xterm 'ctrl-shift-c' and copy and pasted what you have provided in instruction to .Xdefaults but it did not work. – Trismegistos – 2016-07-12T19:07:21.410

@Trismegistos you have to xrdb merge ~/.Xresources (or ~/.Xdefaults) and open another console. There are a few select other things you might have to do, but hopefully you have gotten it working by now and perhaps this might help someone else who can't get it working. – dylnmc – 2016-10-08T15:54:55.960

2@Colin: You still missed the distinction between clipboard and X selection. There are several selections (PRIMARY, SECONDARY, CLIPBOARD), but only one of them is usually called a "clipboard" – the CLIPBOARD selection, because that's where Ctrl-C copies to, and that's where Ctrl-V pastes from. The primary selection is not the clipboard. – user1686 – 2016-11-05T18:14:50.983

@grawity Oh I see how the way I stated it is confusing. I meant clipboard (lowercase) in the sense of any kind of buffer that allows you to cut and paste text. Edited: Another modern wrinkle is the widespread use of touchpads, that makes pasting from the X cut-buffer quite a gamble (what is your three-finger-tap success rate?), so I've assigned an additional xterm hotkey for pasting from the X clipboard by changing the paste-source specifier CLIPBOARD to PRIMARY in Xresources. – Colin – 2016-11-05T22:53:21.353

Note that the mouse wheel nowadays can act as the third mouse button. If your shell supports it, by clicking it you can paste text from the clipboard, as mentioned in the answer. – Jose Faeti – 2017-01-16T08:20:56.707

10Hmm. In Vim, “yank” means copy rather than paste. This seems to make more sense, too. Are you sure about the meaning of this term here? – Konrad Rudolph – 2012-05-07T12:23:53.100

12Yes, I'm sure. Bash inherits the default shortcuts from their Emacs equivalents. – user1686 – 2012-05-07T12:42:39.867

4@grawity: your last comment is a teenie bit misguided. Bash offers two modes of command-line editing, vim-mode and emacs-mode. It just happens that emacs-mode is the default on most installs. That does raise ambiguity in the use of the term yank, even for bash. – rahmu – 2012-05-07T13:46:15.937

1A-ha! I knew the Vimperator developers made a mistake when they switched <C-v> to i in version 3, but I couldn't quite put my finger on why. – Izkata – 2012-05-07T18:08:39.197

48

Use CtrlShiftV for pasting.

Ctrl with other chars is usually used by the shell for special functions.

Akash

Posted 2012-05-07T07:44:30.483

Reputation: 3 682

4So why Linux does not register CTRL+SHIFT for special functions instead; I think copy-paste is more typical by some users than that special functions, right? – Yasser Zamani – 2012-05-07T07:58:21.150

22Shells have existed way before there were graphical Terminals and GUIs with cut and paste functionality, so your argument isn't really valid. @YasserZamani – slhck – 2012-05-07T08:01:07.017

9Ctrl+Shift+V is executed by the terminal emulator (assuming you're using GNOME Terminal) and not by bash itself. If you're ever outside a GUI environment, or if you're using another term emulator, this will probably not work. Do not think this command is portable. – rahmu – 2012-05-07T13:48:34.963

@rahmu Oh, had no idea about that. Use only stock Ubuntu installs. Is there a universal command? – Akash – 2012-05-07T15:46:52.373

2There probably isn't one for accessing the clipboard (only Shift+Ins for the primary selection). Even the clipboard itself is an X11 thing, not accessible from tty's. However, Ctrl+Shift+V is supported by GNOME Terminal, Xfce4 Terminal, KDE Konsole; this covers the most popular GUI environments. – user1686 – 2012-05-08T11:20:59.353

21

Here's your general-purpose copy paste settings with popular terminals:

gnome-terminal (most popular on Linux)
Copy: CtrlShiftC
Paste: CtrlShiftV
Note: Select-to-copy and middle-click to paste also works, but it uses an alternate clipboard.

PuTTY (most popular terminal in Windows)
Copy: (select with mouse, no keyboard interaction)
Paste: Right-click (or more reliably: shiftRight-click)
Note: Apps that take mouse input (like vim and links) can steal Right-click -- shiftRight-click will always work in any app.

OSX Terminal
Copy: AppleC
Paste: AppleV
Note: Apps that take mouse control (like vim and links) may override what it means to select text, in which case copy won't work the way you expect it to. In those cases, hold down Control while you drag the mouse to select. Mouse interaction with apps is disabled by default in your terminal settings, so most people won't even know about this.

tylerl

Posted 2012-05-07T07:44:30.483

Reputation: 2 064

@Ben but right click to paste also works on cmd.exe (and is the only way there, if you don't want to open menu > edit > paste) in quick edit mode. There's no shortcut in pre-win10 command prompt

– phuclv – 2016-11-26T10:24:19.177

Isn't cmd.exe more popular than PuTTY on Windows? :-) – Ben – 2012-05-08T17:09:52.043

@Ben Not as an SSH terminal. – tylerl – 2012-05-08T17:34:04.840

1No, cmd.exe is not an SSH terminal. That is very true. – Ben – 2012-05-08T17:37:04.723

3@Ben: It is not a terminal at all - only a shell. The default terminal in Windows is the "Windows Console" component of csrss. – user1686 – 2012-05-09T04:34:39.000

17

It is a deep rooted tradition that the Ctrl key together with a letter generates ASCII control characters found by subtracting 64 from the upper case letter's ASCII value. This calculation maps Ctrl-A to 1, and so on. For instance Ctrl-I is Tab and Ctrl-J is linefeed.

There is no similar tradition for Ctrl-Shift. Ctrl-Shift-V is not expected to produce any specific character.

Terminal emulators must support tradition by transparently passing through the Ctrl convention, letting it appear as character input to the programs being operated through that terminal window. Terminal-based programs map control keys to commands. For example, Bash uses Ctrl-V as a command which means "take the next character literally". This allows you to embed a control character in the command line. If the terminal steals control keys for its own use, such commands become unavailable. So intercepting Ctrl-V for a meta-function is out of the question (at least in a default configuration).

However, terminal emulators are free to intercept Ctrl-Shift-V which isn't expected to generate a character. Ctrl-Shift-V isn't a standard; it's a Gnome Terminal thing (which may be in some other terminals).

On X-based Unix desktops the convention is that no command is needed to copy. You just select the text. And the middle button pastes that text elsewhere. You will find that it works in Xterm, Gnome Terminal and Firefox alike.

Ctrl-V is a Microsoft Windows convention, which is an imitation of Apple-V from the Macintosh.

Kaz

Posted 2012-05-07T07:44:30.483

Reputation: 2 277

Ctrl-A is 1. How can I try this? My Gnome terminal does nothing when I press Ctrl-A. – robert – 2017-11-03T08:44:05.273

3

It is not exactly subtraction -- traditionally Ctrl has cleared the 6th and 7th bits of the character; because of this, Ctrl+Shift+letter works identically to Ctrl+Letter in most terminals (unless it is explicitly overriden by the terminal, as in the case of copy/paste shortcuts).

– user1686 – 2012-05-08T12:18:43.807

1Because the keys are essentially randomly ordered with respect to the ASCII standard, the program ROM includes several look-up tables that assist in the generation of the ASCII codes. ... Holding own the CONTROL key when another key is pressed causes another table look-up. [VT100 series Technical Manual, 4.4.9.3, Digital]. – Kaz – 2012-05-10T02:40:42.770

1@Linger thanks for the edit. It renders nicely, but there is no way I'm typing all these <kbd> tags in future posts. – Kaz – 2013-05-29T18:10:59.790

3

To me, the simplest way to copy paste in the shell is:

Select the code you want and then past it by clicking the mouse-middle-key

Pedro Lobito

Posted 2012-05-07T07:44:30.483

Reputation: 573

1As long as you have a middle mouse key. – jpierson – 2015-08-29T11:35:08.603

1@jpierson not that I am strongly recommending this, but you can write a small script that simply uses xdotool click 2 to emulate the third-button click for you. Then, in whatever window manager / desktop environment you are in, you can bind this script to a key - say mod i (for insert) or whatever keybindings you might have available (or whatever mod might mean - which really depends where you bind this) – dylnmc – 2016-10-08T16:07:44.897

2

We can use insert keyboard button to do copy and paste(In old keyboards it can be missing)

Copy: CtrlInsert
Paste: CtrlShiftInsert

Bharat

Posted 2012-05-07T07:44:30.483

Reputation: 135

1

you can also use the middle button an a mouse if you are feeling lazy and select a command from either a text document, script or web or forum. once you've selected the intended command simply move to your terminal and click the middle button on the mouse. I use this method as I use puppy linux which doesnt seem to support the normal behaviour of right click and paste. it does in a file handler window, just not in a terminal window. dont know why but I'm quiet pleased I found out about the middle button method, very handy! ;-)

m1cha3ll0w3

Posted 2012-05-07T07:44:30.483

Reputation: 19