Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
8  
Shift-Insert also works –  bonyiii May 7 '12 at 10:57
13  
I prefer Ctrl-Shift-V, personally. –  amalloy May 7 '12 at 18:46
    
You can also use Shift + Insert in most shell environments. –  Fabian May 8 '12 at 9:17
    
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 May 8 '12 at 17:55
    
What if you won't have an Insert key? –  Ben Racicot Oct 1 '13 at 23:46
show 2 more comments

4 Answers

up vote 170 down vote accepted

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 Xerox PARC[unsure] around 1974, later 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 – in GNOME Terminal, use CtrlShiftC and CtrlShiftV.

(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.)

(Thanks to bonyiii for reminding me about the CUA keys.)

share|improve this answer
6  
Hmm. 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 May 7 '12 at 12:23
5  
Yes, I'm sure. Bash inherits the default shortcuts from their Emacs equivalents. –  grawity May 7 '12 at 12:42
16  
+1 for a thorough history lesson –  Phil May 7 '12 at 14:11
4  
@rahmu: I did say default. (Emacs-mode is not only default but also primary mode of operation; even the actual readline commands and bash/readline docs (the cut/paste section) use Emacs terminology.) –  grawity May 7 '12 at 14:17
3  
@grawity Sorry for the discussion in the comments, but I just wanted to see how you did the 'buttons' for the keyboard keys and saw the pony. Made me laugh, thanks. –  SaultDon May 7 '12 at 16:40
show 4 more comments

Use CtrlShiftV for pasting.

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

share|improve this answer
    
So 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 May 7 '12 at 7:58
14  
Shells have existed way before there were graphical Terminals and GUIs with cut and paste functionality, so your argument isn't really valid. @YasserZamani –  slhck May 7 '12 at 8:01
7  
Ctrl+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 May 7 '12 at 13:48
    
@rahmu Oh, had no idea about that. Use only stock Ubuntu installs. Is there a universal command? –  Akash May 7 '12 at 15:46
1  
There 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. –  grawity May 8 '12 at 11:20
add comment

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.

share|improve this answer
    
Isn't cmd.exe more popular than PuTTY on Windows? :-) –  Ben May 8 '12 at 17:09
    
@Ben Not as an SSH terminal. –  tylerl May 8 '12 at 17:34
    
No, cmd.exe is not an SSH terminal. That is very true. –  Ben May 8 '12 at 17:37
    
@Ben: It is not a terminal at all - only a shell. The default terminal in Windows is the "Windows Console" component of csrss. –  grawity May 9 '12 at 4:34
add comment

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.

share|improve this answer
1  
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). –  grawity May 8 '12 at 12:18
1  
Because 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 May 10 '12 at 2:40
    
@Linger thanks for the edit. It renders nicely, but there is no way I'm typing all these <kbd> tags in future posts. –  Kaz May 29 '13 at 18:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.