Why does Ctrl + V not paste in Bash (Linux shell)?
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.
Use CtrlShiftV for pasting.
Ctrl with other chars is usually used by the shell for special functions.
Here's your general-purpose copy paste settings with popular terminals:
gnome-terminal (most popular on Linux)
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
links) can steal Right-click -- shiftRight-click will always work in any app.
Note: Apps that take mouse control (like
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.
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.
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
Yasser Zamani about 1 year
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?
Admin over 11 years
Admin over 11 yearsI prefer
Admin over 11 yearsYou can also use Shift + Insert in most shell environments.
Admin over 11 yearsIn bash itself, I prefer selecting desired text and then pressing middle click. From outside, I prefer CTRL-C then Shift-Insert in bash.
Admin about 10 yearsWhat if you won't have an Insert key?
Admin almost 10 years@BenRacicot,
Admin almost 10 yearsCtrl-Shift-V is not pasting in my clipboard, that's why I asked.
Admin over 9 yearsit doesn't work in windows' command prompt too
Admin about 8 yearsWindows 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.
Admin almost 8 yearsfunny note: superuser.com/questions/675619/… (essentially the same question as this, but about Win) was closed as "primiarily opinion-based"...
Admin over 7 years@LưuVĩnhPhúc: Actually in Windows 10 it finally does.
Admin over 7 yearsUse ^k from the start of the line to copy and ^y to paste. Similar commands for emacs.
Admin almost 7 years@BenRacicot which keyboard doesn't have insert key?
Admin over 5 yearsJFTR,
Ctrl-Shirt-Vwon't work on "older" terminal emulators such as
rxvt. Another case in point is that
Shirt-Insertinserts the contents of the so-called "PRIMARY" selection (the currently-active selection in another GUI application) while
Ctrl-vmost of the time expected to paste the content of the so-called "CLIPBOARD" selection buffer (what most people call "the clipboard" actually).
Admin almost 2 yearsPressing the 3rd mouse button (in my case, pressing the mouse's roller) pastes text from the clipboard into terminal.
Yasser Zamani over 11 yearsSo 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?
slhck over 11 yearsShells have existed way before there were graphical Terminals and GUIs with cut and paste functionality, so your argument isn't really valid. @YasserZamani
Konrad Rudolph over 11 yearsHmm. 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?
rahmu over 11 years@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 over 11 yearsCtrl+Shift+V is executed by the terminal emulator (assuming you're using GNOME Terminal) and not by
bashitself. 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.
badboy24 over 11 yearsA-ha! I knew the Vimperator developers made a mistake when they switched
iin version 3, but I couldn't quite put my finger on why.
user1686 over 11 yearsThere 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 over 11 yearsIt 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).
Ben over 11 yearsIsn't
cmd.exemore popular than PuTTY on Windows? :-)
Alex over 11 years@Ben Not as an SSH terminal.
Ben over 11 yearsNo,
cmd.exeis not an SSH terminal. That is very true.
user1686 over 11 years@Ben: It is not a terminal at all - only a shell. The default terminal in Windows is the "Windows Console" component of csrss.
Kaz over 11 yearsBecause 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, 220.127.116.11, Digital].
Kaz over 10 years@Linger thanks for the edit. It renders nicely, but there is no way I'm typing all these
<kbd>tags in future posts.
jpierson about 8 yearsAs long as you have a middle mouse key.
S RB over 7 yearsSoooo - 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.
Anthony Geoghegan over 7 years@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.
Trismegistos over 7 yearsI 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.
dylnmc about 7 years@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 about 7 years@jpierson not that I am strongly recommending this, but you can write a small script that simply uses
xdotool click 2to 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
i(for insert) or whatever keybindings you might have available (or whatever mod might mean - which really depends where you bind this)
user1686 about 7 years@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.
Colin about 7 years@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.
phuclv almost 7 years@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
Jose Faeti almost 7 yearsNote 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.
robert about 6 years
1. How can I try this? My Gnome terminal does nothing when I press
xpusostomos over 3 yearsWhether that works or not has nothing to do with the shell, but what kind of terminal emulator you are using.. many X based terminals allow this mouse move.
golddragon007 about 3 years@JoseFaeti Yes, from your secondary clipboard that may not have the same content like your ctrl + c clipboard, because linux has two clipboard and you can make even bigger mess. I still don't understand, why they can't adapt the new 'trend'. Other consoles fully support ctrl + c and ctrl + v this. This is both usability and user experience issue...
aff about 3 yearsFor pasting, it's normally just