FUNDAMENTALS A Complete Guide for Beginners
![icon linux](https://linuxsimply.com/wp-content/uploads/2024/05/Linux-Mascot.png)
Emacs is a versatile and flexible text editor available in Linux. Apart from text-based manipulation, it is a powerful tool leveraging operations such as development, version, control, etc. One of the useful features of Emacs is its fast and efficient copy, and paste features. Therefore, this article aims to discuss 2 methods on how to copy and paste in Emacs text editor in Linux. Moreover, it will show how to cut text and subsequently paste it into the Emacs text editor in Linux.
Method 1: Using Keyboard Shortcut
Using keyboard shortcuts is an effective way to copy, cut, and paste a text block in the Emacs text editor. These shortcuts are typically called “keyboard bindings”. To copy a text in Emacs, first, it is necessary to select the specific text. So, place the cursor at the beginning of the region to copy. Then, press CTRL+SPACE to mark the start of the block to select like the image below:
Now, select the text to copy by moving the cursor with the arrow key until the selection is finished. The selected should be highlighted below:
For example, I have selected the text block “copying text with emacs key” using the above keyboard shortcut.
Optionally, to select the entire text buffer in Emacs, use the keyboard shortcut CTRL+X and then press H:
Finally, to paste the text selected, press ALT+W (M-W) to copy the text to the clipboard and press CTRL+Y (C-Y) afterward to paste it:
The snapshot above states that Emacs has copied and pasted the text “copying text with emacs key” at the end of the file in a newline.
Now, to cut the same block of text in Emacs, press CTRL+W (C-W), and finally to paste press CTRL+Y (C-Y) like before:The text block “copying text with” is selected from the sentence “copying text with emacs key bindings” to cut.
Emacs has cut and pasted the selected text block in a newline once specified.
To know more about Emacs keyboard shortcuts, read this article “Emacs Cheat Sheet [Free PDF Download]”
Method 2: Using GUI
Apart from using the keyboard shortcuts for copy, cut, and paste operations in Emacs, using the GUI (Graphical User Interface)-based method is another effective approach. Its user-friendly visual interface of toolbar icons (menu options) lets users copy, paste, and cut text without using the keyboard.
To copy, cut, and paste in Emacs using GUI, there are 3 different toolbar icons:Now, to copy a full text or text block, place the cursor at the start of the text and select the region by moving the cursor with the mouse and click the copy toolbar icon:
Now, click the paste toolbar icon to paste the selected text to the existing file like the image below:So, the text “this line is going to be copied” has been copied via the GUI-based copy and paste buttons.
Similarly, to cut text in Emacs, use the cut button (the scissors icon) and paste as usual like the following image:After clicking the cut button, the selected text will disappear until you paste it into the specified region or location. So, finally, click the paste button to paste the text:
Here, you see Emacs has successfully cut the last sentence of the file hello.txt and eventually pasted it between the texts “bangladesh” and “sri lanka”.
Conclusion
This article has discussed 2 effective methods to copy and paste text in the Emacs text editor in Linux. It has mentioned useful keyboard shortcuts for copying, cutting, and pasting operations. Moreover, it has mentioned how to copy, and paste using the GUI-based available buttons in Emacs. Additionally, the article has shown the cut operation using the same approaches. After reading this guide, you will be able to exploit the copy, cut, and paste features of Emacs and manipulate texts as per your needs and choices.
People Also Ask
How do I copy a block of text in Emacs?
To copy a block of text in Emacs, first, select the text region using a keyboard shortcut or mouse (the one you prefer). Once the text region is selected, press ALT+W to copy the text. Then press CTRL+Y to paste the text. Moreover, press CTRL+W to cut the selected text.
Can I copy and paste text using GUI in the Emacs editor?
Yes, you can copy and paste text using GUI in Emacs. To copy text using GUI in Emacs, select the text region by clicking the mouse’s left button and dragging the mouse to the end of the region to copy. Then click on the copy button to copy the selected text region. Finally, click on the paste button to paste the text.
How to copy text from Emacs to the terminal in Linux?
To copy text from a file in Emacs to the terminal, open the file using the command emacs file_name &. This allows the users to continue using the terminal while Emacs is open with the specified file_name. Then select the text region and press ALT+W (M-W) to copy the text. Finally, paste the text into the terminal using standard commands. For instance, if you are using Ubuntu, paste the text in the terminal pressing CTRL+SHIFT+V or right-clicking the mouse and subsequently clicking paste.
Can I use Emacs to copy to the clipboard and paste from the clipboard?
Yes, you can. When you copy text using ALT+W (M-W) in Emacs, it copies the selected text to both the Emacs internal history (called Emacs kill ring) and the system clipboard. Here, the advantage is the system clipboard allows one to copy text within other applications outside Emacs. Similarly, Emacs can also paste selected text from the system clipboard. This is because the latest Emacs versions can interact with the system clipboard by default apart from using the kill ring (internal history buffer).
Is it possible to cut text using the Emacs text editor in Linux?
Yes, it is possible to cut text using the Emacs text editor in Linux. To cut text, select the text region first by dragging the mouse or by pressing CTRL+SPACE and the right arrow afterward. The selected text region will be highlighted. Then press CTRL+W to cut the selected portion of text. Alternatively, you can click the GUI-based cut button (the button with the scissors icon) to cut the text once you have selected it.
How to undo the last edits of a file in Emacs?
To undo the last edits of a text file in Emacs, press CTRL+X first and then press U. This will undo the changes you made to the file. In this way, you can undo all the available changes made to the file. Alternatively, you can click on the Undo button from the Emacs window to easily undo the last edits of the file you are working with.
How to cut, copy, and paste a text in Emacs text editor in Linux?
To cut, copy, and paste text in Emacs in Linux, select the text by using the cursor (either using a mouse or keyboard shortcut). Then press CTRL+W (C-W) to cut the selected text. To copy the selected text, press ALT+W (M-W). Finally, to paste the selected text, move the cursor location to where you want to paste it and press CTRL+Y (C-Y). Alternatively, you can use the GUI-based Emacs toolbar icons to cut, copy, and paste text in Emacs.
What are the most basic commands to copy, cut, and paste in Emacs?
The most basic commands to copy, cut, and paste in Emacs text editor are the keyboard shortcuts (also called keyboard bindings) ALT+W (M-W), CTRL+W (C-W), and CTRL+Y (C-Y) respectively. However, first, you have to select the text region to copy, cut, and paste. To do this, use keyboard shortcuts or drag the cursor by using the mouse.
Related Articles
<< Go Back to An Overview of Emacs Text Editor in Linux | Linux Text Editors | Learn Linux Basics