Lesson 5 – Editing Files

The emacs editor

This is the simplest Linux editor that I have seen. In order to start the program, just type “emacs” at the command prompt:


If you want to start a new file, but also specify the name of the file, then use the following format of the command (make sure that you do not already have a file named “filename” in your current directory):

    >emacs filename

If you want to open an existing file, use the same format as above, but make sure that a file named “filename” already exists in your current directory.

Once in the program, you can use the menus at the top of the window to perform certain tasks. Please note that “Save Buffer…” is the item that you select from the “Files” menu in order to save your work.

The vi editor

To start a vi session, just type:


To start a new file, use the following command:

    >vi filename

The command above will start a new file, called “filename“, as long as there is not a file already with that name in the current directory. If you want to open an existing file, called “filename“, use the same command above.

There are no menus in vi, so all the commands are entered using the keyboard. Following is a list of some of the most common commands in vi:

Command Description
:q! + Enter key Closes the program without saving changes
:w + Enter key Saves changes
:wq + Enter key Saves changes and then closes the program
l Moves the cursor one space to the right
h Moves the cursor one space to the left
j Moves the cursor down one line
k Moves the cursor up one line
i Inserts text at the cursor’s position
a Inserts text one space after the cursor’s position (appends text)
Esc key Takes you out of input mode (always takes you to command mode)
x Deletes the character at the cursor’s position
dd Deletes the current line
Y (Shift + y) Copies the current line
p Pastes text after the cursor’s position
P (Shift + p) Pastes text before the cursor’s position
/searchstring Searches forward through the file for searchstringto find the next occurrence of searchstring, press the n key.

For the commands that are preceded by a “:” (colon), or a “/” (forward slash), the commands that you type will appear at the bottom left of your window. For more information about vi and its commands, check out the man pages.

Continue to Lesson 6 – SFTP
Return to index of lessons.

Last revised May 9, 2002.