- Select/copy/paste in terminal using only the keyboard
- 5 Answers 5
- Буфер обмена в Linux (копирование и вставка)
- Буфер копирования
- Буфер выбора (первичный буфер)
- Копирование и вставка в терминале
- How to Copy and Paste in Linux and Ubuntu Terminal
- Using Keyboard Shortcut
- Using Mouse Right-Click Context Menu
- Using Mouse Middle Key
- Conclusion
- About the author
- Swapnil Tirthakar
Select/copy/paste in terminal using only the keyboard
I’m looking for a way to select, copy and paste the text in the terminal completely without the mouse. I’ve been using tmux until now, but I find its key combinations a bit complex for everyday use of copy & paste, and I’m now looking for alternatives. Do you guys have any suggestions? To be clear, this is not about piping to the clipboard but about selecting the text as it’s possible in e.g. tmux !
See my answer here: askubuntu.com/a/756348/295286. Ive made a function that will copy whatever text is in front to clipboard. That works for copying the commands. As for output, it has to be piped
Okay guys this has nothing to do with stdout- it’s about moving a cursor to some previous printed text Select it and Copy/paste it to the current line of input in the terminal:-D Sorry for not being more precise in description.
The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself.
5 Answers 5
I always use Ctrl + Shift + C and Ctrl + Shift + V to copy and paste in my (non tmux) terminal.
You can change these keyboard shortcuts in the keyboard preferences of your (non-tmux) terminal.
If however you want to keep using tmux you can also change the keyboard shortcuts of tmux by adding commands to ~/.tmux.conf . simply add the following in that file:
bind-key -n [shortcut. for example Ctrl+v is C-v] [what you want to do. for example 'new-window' etc]
You don’t need the command prefix key to execute the commands in the ~/.tmux.conf file.
For more info about the things available for ~/.tmux.conf check this link
Very rudimentary copying and pasting can be done using this however for a bit more usefulness I recommend using a Vim-style copy/paste config.
Enabling a Vim-style of copy/paste can be done with this config file or another config file. These do however require the use of the prefix key.
Someone even made a tmux extension to simplify the copy/paste action to the system clipboard in tmux. It might be worth a look.
If you want an alternative for Tmux you might try dvtm ( sudo apt-get install dvtm dtach ). I haven’t used it myself but it looks like it has similar options.
Буфер обмена в Linux (копирование и вставка)
Хочу рассказать о некоторых особенностях буфера обмена в Linux. О буфере копирования и про буфер выбора (первичный буфер), а также про копирование и вставку текста в терминале.
Буфер копирования
Стандартно для копирования и вставки объектов в Linux используются сочетания клавиш Ctrl+C и Ctrl+V. При копировании текст (или любой другой объект) в таком случае попадает в обычный буфер копирования. Затем вы можете вставить этот текст в другом месте.
Буфер выбора (первичный буфер)
В Linux существует еще буфер выбора или первичный буфер. Текст, который вы выделяете в любой программе, автоматически попадает в буфер обмена! Это удобно, выделил текст, открыл другое окно и вставил этот кусок текста. Есть некоторые исключения, но они незначительны. Например, у меня в Ubuntu это не работает, если программа использует JVM (Java Virtual Machine).
Кстати, именно этим объясняется следующие поведение. Вы выделили текст в программе, затем открыли другую программу и выделили какой-нибудь текст в ней. После этого, выделение текста в первой программе автоматически снимется, а текст который вы выделили последним, попадет в буфер выбора.
Копирование и вставка в терминале
В терминале для копирования и вставки не работают стандартные сочетания Ctrl+V, Ctrl+C. Это связано с тем, что исторически Ctrl+C это сочетание клавиш для прерывания текущего процесса. Поэтому, для копирования и вставки при работе в терминале используются сочетания Ctrl+Insert и Shift+Insert соответственно. В Gnome терминале и, наверное, во многих других также работают сочетания Shift+Ctrl+C и Shift+Ctrl+V. Они же указаны в главном меню программы в разделе Правка.
Также в терминале работают сочетания клавиш Ctrl+U, чтобы вырезать текст; и Ctrl+Y для вставки текста. Сочетание Ctrl+U работает особенным образом — в буфер копируется вся текущая строка, введенная в терминале, независимо от того, выбрали вы какой-нибудь текст мышкой или нет, а сама строка пропадает с экрана.
How to Copy and Paste in Linux and Ubuntu Terminal
When you switch to Linux from Microsoft Windows, especially if you are a programmer, there is a possibility that you might struggle to copy and paste commands or lines in the Linux Terminal window.
Even when I ported to Ubuntu from Windows a decade ago, I struggled to copy and paste lines in the Linux terminal. At that time, I thought I’m the only user struggling to copy and paste. However, while searching on the Internet, I realized that it is a global problem.
The reason is a keyboard shortcut and mouse keys to copy and paste lines in the Linux terminal windows are not the same as the ones we use on Windows.
The key bindings for copy and paste operations are dependent on the specific terminal emulator you are using. In Linux, by default CTRL + C key binding is used for sending an interrupt signal to the command running in foreground. Hence, the Linux terminals do not use the standard CTRL + C and CTRL + V for copy and paste operations.
Using Keyboard Shortcut
On Ubuntu and other Linux distributions, you have to use CTRL + SHIFT + C combination of keys to copy text from a terminal or a text editor.
To copy a text or line of code from the browser, you can use the generic CTRL + C combination or CTRL + SHIFT + C. Then, to paste this line of code into the terminal, you need to use CTRL + SHIFT + V keys.
You have to use these key combinations in Ubuntu to perform copy and paste operations, especially in the Linux Terminal.
Using Mouse Right-Click Context Menu
The other way to copy and paste in the Linux terminal is to use Mouse right key context menu.
To copy the text or line in terminal, select the text then right click and select copy. Now, to paste the selected text, right-click and select paste from context menu.
Using Mouse Middle Key
This method is not so much popular among Linux users but still effective on some Linux distributions. In this method, you need to select the text you want to copy and paste. Then, press the scrolling wheel button, which is the middle button on the mouse, to paste the selected text.
This is how you can copy and paste text in Linux terminal. It is simple yet confusing for new Linux users, especially those switching to Linux from Windows or Mac. The mentioned methods may or may not work in various Linux distributions for the reason mentioned earlier in this article.
Conclusion
The copy and paste commands in the Linux and Ubuntu Terminals are different from Microsoft Windows and Mac. There are three methods to copy and paste in the Linux and Ubuntu Terminal. These methods are the use of the specific keyboard shortcuts, the use of the mouse right-click menu, and the use of the mouse middle key. When you implement the methods provided, you can successfully copy and paste in the Linux and Ubuntu Terminals. I hope this article helped you efficiently use the copy and paste command. To learn more, check out the other articles on LinuxHint.com.
About the author
Swapnil Tirthakar
A Software Engineer who loves football and passionate about traveling. I often spend my free time playing with gadgets and exploring new possibilities in tech world. I am Linux enthusiast and have about 6 years of experience in web development. I have good command on Python, Java, SQL and system security.