Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an empty file in emacs?

How can I create an empty file from emacs, ideally from within a dired buffer?

For example, I've just opened a Python module in dired mode, created a new directory, opened that in dired, and now need to add an empty __init__.py file in the directory.

If I use C-x C-f __init__.py RET C-x C-s then emacs doesn't create the file because no changes have been made to it. I would have to type in the file, save it, delete my typing and then save it again for that to work.

Thanks

like image 827
Singletoned Avatar asked Apr 07 '10 11:04

Singletoned


People also ask

How do you create an empty file?

From within Windows, right-click in the area you want to create the file. For example, right-click the desktop to create a new text file on the desktop. In the drop-down menu that appears, select New and choose Text Document.

What is the command to create an empty file in Linux?

Basically, there are two different commands to create a file in the Linux system which is as follows: cat command: It is used to create the file with content. touch command: It is used to create a file without any content. The file created using touch command is empty.

What is the Emacs command to save a file?

1) Saving Files in Emacs Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s. Users can also save the current buffer to some other file name by hitting the keys Ctrl + x, followed by Ctrl + w.


2 Answers

You can use the touch command:

M-! touch __init__.py RET 
like image 107
Dani Avatar answered Oct 03 '22 09:10

Dani


The following works:

C-x b __init__.py RET C-x C-w RET

If you're in a dired buffer the file will be saved in the directory show here.

The trick is to first create an empty buffer by switching to a name that doesn't exist. Then write out the file.

like image 21
slu Avatar answered Oct 03 '22 10:10

slu