Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create new file from dired mode?

Tags:

file

emacs

dired

I want to create a new file in dired mode. Is there "create new file" command in dired mode ? For example, When I type "c" in dired mode, it creates "untitled.txt". It's very simple , but I can't find it.

like image 850
Kei Minagawa Avatar asked Nov 30 '13 12:11

Kei Minagawa


People also ask

How do I create a dired folder?

The command + ( dired-create-directory ) reads a directory's name, and creates that directory. It signals an error if the directory already exists.

How do I create a new file in Emacs?

To create a new file, use Control-X-Control-F, just as if the file already existed. When emacs asks you for the file name, type in the name you want your new file to have, and emacs will create the file, and display an empty buffer for you to type in. Emacs will perform file name completion for you.

How do you use dired?

To enter into a directory, move to its listing in the Dired buffer, and simply hit the return key. To view a file, you can place the cursor on its entry and use the f or v key, or simply hit the return key.

How do I move files in dired?

Open dired for a directory containing files you want to work with. Then use C , R , or D when the cursor is on the line of a file to copy, rename/move or delete the file, respectively. This can also be done for multiple files by marking them.


2 Answers

Just press C-x C-f. This will prompt for a filename, using the current directory of the current buffer as the directory to put it in. For a dired buffer, its current directory is simply the directory you are looking at.

like image 51
Robin Green Avatar answered Oct 21 '22 00:10

Robin Green


If you want c in Dired mode to do what C-x C-f does, the answer is trivial:

(define-key dired-mode-map "c" 'find-file) 

Or if you want it to have the name untitled.txt then:

(define-key dired-mode-map "c"   (lambda () (interactive) (find-file "untitled.txt"))) 
like image 33
Drew Avatar answered Oct 21 '22 02:10

Drew