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.
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:
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
).
I tried C-x h but it's not working. It puts the cursor in the beginning of the file and says mark set. But if I try to paste then it does not paste the file contents.
You probably don't have transient-mark-mode enabled. Do M-x tranient-mark-mode. This will show your selected region. Once you do C-x h, make sure you are copying with C-w.
Thanks. It's working after I did M-x transient-mark-mode. Thanks again for the quick response.
Sajib Mahmood: Note that
C-x h
should still work regardless of that mode; you just won't see the marked region. SoC-x h M-w
should always copy the buffer's contents. Also,transient-mark-mode
is enabled by default, so you may want to figure out why it's disabled in your config.Good point. Also, 21.4 is nine years old. Updating would be well worth considering.