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

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?


Solution 1:

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.

Solution 2:

Use CtrlShiftV for pasting.

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

Solution 3:

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.

Solution 4:

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.

Solution 5:

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