官术网_书友最值得收藏!

Creating, editing, and saving files

Now that you can log in and move easily between directories and see your files, you'll want to be able to edit those files. To do this, you'll need a program that allows you to edit the characters in a file. If you are used to working on Microsoft Windows, you have probably used programs such as Microsoft Notepad, WordPad, or Word to do this. These programs are not available in Linux. There are several other choices for editors, all of which are free. In this chapter, you will use an editing program called Emacs. Other possibilities are programs such as nano, vi, vim, and gedit. Programmers have strong feelings about which editor to use, so if you already have a favorite, you can skip this section.

Note

If you want to use nano as an editor, it is already available on the Raspbian distribution. For more information on nano, see http://www.nano-editor.org/.

If you want to use Emacs, download and install it by typing sudo apt-get install emacs. Once installed, you can run Emacs simply by typing emacs filename, where filename is the name of the file you want to edit. If the file does not exist, Emacs will create it. The following screenshot shows what you will see if you type emacs example.py on the prompt:

Note that, unlike Windows, Linux doesn't automatically assign file extensions; it is up to you to specify the kind of file you want to create. The Emacs editor also indicates, in the lower-left corner of the screen, that you have opened a new file. Now, if you are using Emacs in the Raspbian GUI interface, either because you have a monitor, keyboard, and mouse hooked up or because you are running vncserver, you can use the mouse in much the same way as you do in Microsoft Word.

However, if you are running Emacs from SSH, you won't have the mouse available. So you'll need to navigate the file using the cursor keys. You'll also have to use some keystroke commands to save your file, as well as accomplish a number of other tasks that you would normally use the mouse to select. For example, when you are ready to save the file, you must press Ctrl + X and Ctrl + S and that will save the file under the current filename. When you want to quit Emacs, you must press Ctrl + X and Ctrl + C. This will stop Emacs and return you to the Command Prompt.

The following are some Emacs keystroke commands that you might find useful:

Now that you have the capability to edit files, you'll use this capability to create programs in the next section.

主站蜘蛛池模板: 琼中| 哈巴河县| 天峻县| 科技| 揭西县| 敖汉旗| 佳木斯市| 始兴县| 哈密市| 哈巴河县| 黄山市| 靖远县| 高雄市| 阿鲁科尔沁旗| 泾源县| 葵青区| 怀仁县| 武邑县| 突泉县| 乐亭县| 馆陶县| 佛坪县| 洪江市| 雷州市| 双峰县| 页游| 商洛市| 黄平县| 安阳市| 平谷区| 得荣县| 宝应县| 德令哈市| 星子县| 思南县| 南京市| 银川市| 扶余县| 阳山县| 江阴市| 兰考县|