Access Keys:
Skip to content (Access Key - 0)

How to move regions of text (cut and paste) in emacs

The cut and paste behavior of Emacs is similar to most other standard X applications.

  • Dragging with the LEFT mouse button now puts the selected region in the kill ring so you can paste it into other X applications. The old method of clicking at the beginning with the LEFT mouse button and at the end with the RIGHT mouse button still works, but the cursor will end up at the end of the region instead of at the beginning.
  • Double and triple clicks with the LEFT mouse button now select the word or line surrounding where you click. If you drag after the last click, you can select a range of words or lines.
  • Clicking and dragging the RIGHT mouse button now extends a previously mouse-selected region, from the end of the region that is closer to where you click.
  • As before, clicking the RIGHT mouse button in the same place kills the region selected.

The following commands will also allow various specific cut-and-pastes:

  • Ctrl-<space> or Ctrl-@ - Either of these commands will set a mark. A mark is an invisible pointer which will be used to mark the starting character of the region you wish to delete or move. If you place the mark in the wrong place, you can set it elsewhere with the same command.
  • Ctrl-w - This command will kill all of the text between the mark location and the current emacs cursor position. This text can be retrieved with the following command unless you kill another block of text.
  • Meta-w - This command will "save" all of the text between the mark location and the current emacs cursor position; it can then be retrieved with the following command unless you kill/save another block of text.
  • Ctrl-y - This command will yank back the text which was deleted most recently with the above command. The text will be placed at the current emacs cursor location. You can yank back the text as many times as you wish.
  • Meta-y - When you kill or copy a region of text, it doesn't forget about previous kills. Instead, it keeps track of them in a "stack" fashion. If you want to yank the region you killed before the last one, hit Ctrl-y to yank, and then Meta-y to yank the previous kill instead of the one you just retrieved. You can keep hitting Meta-y as many times as you like, if you want to recover something killed a while back. The maximum number of kills remembered at any given time defaults to 30.
  • Ctrl-x u - This is the undo command. This is useful if you yank back text at the wrong location or sometimes if you delete something you didn't mean to. Each time you repeat this command, emacs will undo a previous change to your file.

Please note that when you use Ctrl-w or Meta-w to put a region of text in the kill ring, it will become the current X selection. Likewise, when you use Ctrl-y to grab a region of text from the kill ring, it will use the current selection if you've selected text recently.

To disable this behavior, place the following lines in your .emacs file:

(setq interprogram-cut-function nil)
(setq interprogram-paste-function nil)

IS&T Contributions

Documentation and information provided by IS&T staff members


Last Modified:

June 24, 2020

Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
Labels:
olc-emacs olc-emacs Delete
emacs emacs Delete
move move Delete
text text Delete
cut cut Delete
paste paste Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
Feedback
This product/service is:
Easy to use
Average
Difficult to use

This article is:
Helpful
Inaccurate
Obsolete
Adaptavist Theme Builder (4.2.3) Powered by Atlassian Confluence 3.5.13, the Enterprise Wiki