Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12472
  • 博文数量: 14
  • 博客积分: 560
  • 博客等级: 中士
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-17 16:40
文章分类
文章存档

2010年(14)

我的朋友
最近访客

分类: LINUX

2010-09-20 16:53:20

1.7. Opening a File
1.7. 打开一个文件

You can open a file by specifying the filename when you start Emacs from the command line or by typing C-x C-f (the long command name is find-file).
    当你通过命令行打开Emacs时,可以指定文件名来打开文件,或者按C-x C-f打开文件(对应的长指令名为:find-file).

The paper icon on the toolbar also runs this command. In some applications, a similar icon simply creates a new, unnamed file (e.g., Document1 in Word). Emacs expects you to provide a filename, as we'll see in a moment.
    工具栏上的白纸图标也可以执行这个指令。在一些应用程序中,相似的图标会创建一个新的,未命名的文件(例如:word程序中文档1)。我们马上会看到Emacs希望你提供一个文件名。

Press: C-x C-f
按:C-x C-f


Emacs prompts you for a filename.
Emacs会请你输入一个文件名。


To press C-x C-f, hold down Ctrl, press x and then press f. Now release Ctrl.
要按C-x C-f,按住Ctrl,按x再按f,然后放开Ctrl。

After you press C-x C-f, Emacs uses the minibuffer to ask you for the filename. Whenever Emacs wants input from you, it puts the cursor in the minibuffer. When you're done typing in the minibuffer, press Enter.
按完C-x C-f后,Emacs用迷你缓冲区提示你输入文件名。当Emacs希望你输入时,它就把光标移动到迷你缓冲区。当你完成迷你缓冲区的输入时,按回车键。

Type: newfile Enter
输入:文件名 回车


Emacs starts another buffer with the new file in it.
Emacs为新文件启动另一个缓冲区。


What if you try to read the same file twice? Instead of creating a new buffer, Emacs just moves you to the buffer the file is in.
如果你尝试打开同一文件两次会怎样?Emacs不是创建一个新的缓冲区,而是显示已经打开的那个缓冲区。

You can also open a file in Emacs by dragging and dropping it on an Emacs window or on the Emacs icon.
你也可以通过把文件拖曳到Emacs窗口或者Emacs的图标上来打开文件。

Now is a good time to try typing if you haven't already done so. You may find yourself wanting to learn more about cursor movement and editing; that's fine. Feel free to skim the rest of this chapter and go on to Chapter 2. We recommend that you read the sections on saving files and exiting Emacs. There's also a table of commands at the end of this chapter for future reference. If you'd like to learn more about working with files as well as some shortcuts, stay with us through the rest of the chapter.
如果你还没打开文件就快试试吧。你会发现你更需要学习一些光标移动和编辑的内容,好!随便略读一下本章其他内容然后看下第二章。最好看一下保存文件和离开Emacs的章节。如果你想了解更多关于文件操作的快捷键,继续阅读本章后面的内容。

1.7.1 If You Read the Wrong File
1.7.1 如果你打开了错误的文件

If you happen to read the wrong file, an easy way to get the right file is by typing C-x C-v (for find-alternate-file). This command means "Read a different file instead of the one I just read." After typing C-x C-v, Emacs puts the name of the current file in the minibuffer; you can then correct a typo or the path, the most common reasons for finding the wrong file. Make the correction and press Enter. Emacs replaces the buffer's contents with the alternate file.
如果你打开了错误的文件,一个简单的方法来打开正确的文件就是按C-x C-v(表示:find-alternate-file).这个指令的意思是:“打开一个不同的文件来替换当前文件”。按完C-x C-v后,Emacs将当前文件名显示在迷你缓冲区中;你就可以修正文件名或路径错误,这个最常出现的打开文件错误的原因。修改后按回车键。Emacs将新文件的内容替换到当前缓冲区内。

1.7.2 Letting Emacs Fill in the Blanks
1.7.2 让Emacs自动补全

Emacs has a very helpful feature known as completion. If you want an existing file, you need only type the first few letters of the name, enough to uniquely identify the filename. Press Tab, and Emacs completes the filename for you. For example, suppose you are trying to find a file called dickens.
Emacs一个很有用的功能就是自动补全。如果你想打开一个现有文件,你只需输入文件名的前几个字符,这几个字符足以标识指定的文件。按Tab键,Emacs自动补全文件名。假设你要打开文件dikens.

Type: C-x C-f di
输入:C-x C-f di


After C-x C-f, Emacs prompts you for the filename; type the first few letters.
按完C-x C-f,Emacs提示你输入文件名;输入前几个字母。


Press: Tab
按:Tab

When you press Tab, Emacs fills in the rest of the filename.
按完Tab,Emacs将文件名自动补全。


Press: Enter
按:回车

Emacs reads the file dickens.
Emacs打开文件dickens.


If more than one file starts with di, Emacs displays a window with various files that start with that string. You select one by typing a few more characters (enough to identify your file as unique) and pressing Tab again. Or you can select one of the alternatives with the mouse or by pressing PgUp to move to the completions window, moving to the desired option, then pressing Enter.
如果不只一个文件以di开头,Emacs会窗口中显示所有以di开头的文件名。你得输入更多的字符(必须足以标识唯一文件)来打开想要的文件,然后再按Tab键。或者你可以用鼠标选择文件,也可以按PgUp将光标移动到“completions”窗口,移动到需要的选项,按回车键。

Completion also works for long command names. It's a wonderful Emacs feature that can save you time—and show you some commands you might not know existed in the process. Chapter 14 provides more details on the glories of completion.
自动完成也用于补全长指令名称。这是个不错的功能,它即可以节省时间,也可以向你展示一些现有的而你还不知道的指令。第14章有更多关于自动完成的赞誉。

1.7.3 Inserting and Appending Files
1.7.3 插入或合并文件

If you want to insert one file into another, you simply move to the appropriate location in the file and type C-x i. (Yes, we know, we haven't told you how to move around in a file yet. Use the arrow keys for now and we'll teach you the "real" Emacs cursor movement commands in Chapter 2.) To append a file, move to the end of the file (M->) and type C-x i. As with C-x C-f, Emacs prompts you for the filename in the minibuffer.
如果你想把一个文件插入到另一个,移动到适当的位置,按C-x i.(我们还没有介绍如何移动光标,先使用箭头移动。我们会在第2章介绍Emacs如何移动光标。)要追加文件,移动到文件尾部(M->)并输入C-x i。和C-x C-f一样,Emacs让你在迷你缓冲区输入文件名。

1.7.4 How Emacs Chooses a Default Directory
1.7.4 Emacs如何选择默认路径

When you use any command that asks for a filename (such as C-x C-f), Emacs displays a default directory in the minibuffer and asks you to type the rest of the filename. How does Emacs choose the default directory? The default directory is taken from the buffer that the cursor is currently in. If you are editing a file in your home directory when you type C-x C-f, Emacs assumes you want to edit another file in your home directory. If you are editing the file /sources/macros/html.macs then Emacs makes the default directory /sources/macros. If you want to find a file in another directory, edit the default directory that Emacs displays.
当你使用任何需要输入文件名的指令(例如C-x C-f)时,Emacs在迷你缓冲区显示一个默认路径,并让你输入文件名称。Emacs如何选择默认路径?默认路径来自光标所在缓冲区代表的文件所在的路径。如果你当前编辑的文件在用户目录下,按C-x C-f后,Emacs假设你想打开用户目录的另一个文件。如果你在编辑文件 /sources/macros/html.macs,然后Emacs设定默认目录为 /sources/macros.如果想在其他目录下查找文件,编辑Emacs显示的默认路径。
阅读(320) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~