How to copy/select a whole file or buffer in Emacs?

Sajib Mahmood picture Sajib Mahmood · Mar 20, 2014 · Viewed 38.1k times · Source

Is there any command to select the whole file contents in Emacs?

For example, Control+a selects whole contents of a file in Notepad, Notepad++, etc.

I can select whole contents using the mouse, but it's inconvenient for large files. I found the basic Emacs commands here and here, but could not find what I am looking for.

Answer

keelerm picture keelerm · Mar 20, 2014

C-x h will select the entire buffer.

You can search for help within Emacs using the built-in help system.

C-h f will look for help for specific functions. In this case, you could have searched for whole-buffer to find mark-whole-buffer.

Other help commands of interest would be:

  • C-h m to show available commands for the current modes
  • C-h v for help related to variables
  • C-h k to find which functions keys are bound to
  • C-h w to see which key bindings are defined for a given function
  • C-h ? to see which other options are available.

Note that C-x h will only highlight all the text. To actually copy the selected text, you must use C-w for cut (kill-region) or M-w for copy (kill-ring-save).