简体   繁体   English

在Emacs中创建一个文件时,无法打开目录

[英]When I create one file in Emacs, I can not open the directory

I use Cx Cf and C -X Cs to save a file to directory "test", then I can not open the test directory with "tab", it says "Dired (directory): ~/test.....". 我使用Cx Cf和C -X Cs将文件保存到目录“ test”,然后无法使用“ tab”打开测试目录,它显示“ Dired(目录):〜/ test .....”。

I want to know what is the wrong and the correct method to create a file in emacs, thanks! 我想知道在emacs中创建文件的错误和正确方法,谢谢!

Emacs distinguishes between files and buffers . Emacs区分文件缓冲区 You do all your editing in buffers, which do not necessarily have to be associated with a file (see, eg, the *scratch* buffer). 您可以在缓冲区中进行所有编辑,缓冲区不一定必须与文件关联(例如,参见*scratch*缓冲区)。 However, you often want to edit a buffer that is associated with a file. 但是,您通常要编辑与文件关联的缓冲区。 In that case you visit (Emacs lingo for "open") said file with Cx Cf . 在那种情况下,您使用Cx Cf 访问 (Emacs术语为“ open”)。

Let's say you have a directory "test" in your home directory, and in that directory a single file "foo.txt". 假设您的主目录中有一个目录“ test”,而在该目录中有一个文件“ foo.txt”。 If you want to edit the contents of that file, visit it by typing: 如果要编辑该文件的内容,请输入以下内容进行访问:

Cx Cf ~/test/foo.txt RET Cx Cf〜/ test / foo.txt RET

That's easy enough: now you get a new buffer in Emacs which is conveniently named after the file you're visiting ("foo.txt"). 这很容易:现在,您在Emacs中获得了一个新缓冲区,该缓冲区以您正在访问的文件(“ foo.txt”)方便地命名。 If you want to store changes you've made in the buffer back to the associated file, you type Cx Cs , and Emacs will write the contents of the buffer to the file "~/test/foo.txt". 如果要将所做的更改存储回关联文件,请键入Cx Cs ,Emacs会将缓冲区的内容写入文件“〜/ test / foo.txt”。

This mechanism also works for files that do not exist when you start editing! 此机制还适用于开始编辑时不存在的文件!

If you type, say, 如果您输入,说,

Cx Cf ~/test/bar.txt RET Cx Cf〜/ test / bar.txt RET

You get a buffer associated with a (yet non-existent) file "bar.txt" in the directory "~/test". 您会在目录“〜/ test”中获得与(尚未存在的)文件“ bar.txt”关联的缓冲区。 Again, you can edit that buffer to your liking and then save the buffer with Cx Cs . 同样,您可以根据自己的喜好编辑该缓冲区,然后使用Cx Cs保存该缓冲区。 The first time you do that, a new file is created. 第一次执行此操作时,将创建一个新文件。

If you want to create a buffer named "baz" that is not associated with any file, type 如果要创建不与任何文件关联的名为“ baz”的缓冲区,请键入

Cx b baz RET Cx b baz RET

Since it is not associated with a file yet, typing Cx Cs in that buffer will prompt you to specify a file-name. 由于它尚未与文件关联,因此在该缓冲区中键入Cx Cs将提示您指定文件名。 After saving, the buffer will be associated with the file you specified. 保存后,缓冲区将与您指定的文件关联。

Finally, if you're in a buffer that is associated with a file, but you want to save it to a different file, you can do so with Cx Cw , which will give you the same prompt as in the previous case. 最后,如果您位于与文件关联的缓冲区中,但想将其保存到其他文件中,则可以使用Cx Cw进行操作 ,这将为您提供与前一种情况相同的提示。 Again, the buffer will be associated after saving with the file you provide. 同样,缓冲区将在保存后与您提供的文件关联。


Tab completion does work in all of the commands that ask you for a file name. 制表符补全在要求您输入文件名的所有命令中都有效。 If you think it doesn't then it might be because the file you think should be completed does not exist (also beware of upper-/lower-case distinctions in file names), or because another file with the same prefix forbids further disambiguation. 如果您认为不正确,则可能是因为您认为应该完成的文件不存在(还请注意文件名中的大小写区分),或者因为另一个具有相同前缀的文件禁止进一步进行歧义消除。 Tapping TAB twice should list the available completions in a temporary buffer, letting you continue specifying the path name until it is complete. 两次敲击TAB应该会在临时缓冲区中列出可用的补全,让您继续指定路径名,直到完成为止。


Dired mode is pretty much orthogonal to all of the above. Dired模式几乎与上述所有内容正交。 It is a mode for "editing" directories, ie, doing file system operations. 这是用于“编辑”目录(即执行文件系统操作)的模式。 You invoke it by typing Cx d , which you may have typed accidentally?! 您通过键入Cx d来调用它,而您可能不小心键入了它? It is quite powerful, but also quite complex. 它功能强大,但也很复杂。 See here for its documentation. 请参阅此处获取其文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM