How it works
The Unix command vi starts up the visual editor.
Typing vi followed by a file name will automatically open the file.
After issuing the command, the appearance of your screen changes. Rather than seeing the shell prompt, the content of the file filename.txt appears on the screen. If filename.txt hadn't existed before you invoked the vi command, the screen will appear mostly blank.
vi filename.txt
Modes
One of the fundamental concept to keep in mind when using vi is that three modes exist: command, insert, and visual.
In command mode, everything you type on the keyboard gets interpreted as a command.
In insert mode, most everything you type on the keyboard gets interpreted as characters and will appear in your file--letters, numbers, punctuation, line returns, etc.
When you are in insert mode, you can switch to command mode by pressing the Esc key on your keyboard (this is often at the left and upper portion of your keyboard).
When you are in command mode, there are many keys you can use to get into insert mode, each one gives you a slightly different way of starting to type your text. For example, if you are in command mode, you can simply type i on your keyboard to enter insert mode (i stands for insert). Then, the characters you type go into the file.
Basic commands
h = move one character to the left
l = move one character to the right
k = move up one line
j = move down one line
[ctrl] b = move back one screen
[ctrl] f = move forward one screen
quit Vi without saving anything (you'll lose any changes you made when using this command) type: :q!
save/write the file you're working on without exiting type: :w followed by a filename
save/write your file and quit the vi editor in one step by typing: :wq
Nano is freely available under the GPL for Unix and Unix-like systems.
It is a keyboard-oriented editor, controlled with key combinations, i.e. the "control" key (denoted by "^") PLUS certain letter keys.
^O : saves the current file
^W : goes to the search menu
^G : gets the help screen
^X : exits
Launch the editor by typing "nano" at the shell prompt. An overview of available commands is given at any time at the bottom of the editor screen.
nano
Open an existing file by typing "nano" followed by the file name.
nano file1.txt
If you modify the file, when you exit you will be asked whether to save the changes and the name of the file to save.
While holding down Ctrl key, press \
Enter your search string at prompt and press return
Enter your replacement string at prompt and press return
Respond to "Replace this instance" option menu:
Y to replace current instance
N to skip current instance
A to replace all instances
Note: The search string can also be a regular expression.
Prior to starting this demonstration, you should set up your unix directory according to the instructions in Unix utilities
emacs is a powerful text editor with extensive functionality.
1) Control mode is activated by pressing and holding the <ctrl> key while pressing the second key. This process is written as:
C-key
This example shows the result after C-s (search):
2) Meta-mode is activated by pressing and releasing the <ESC> key followed by some other key that activates a sub-menu of commands. This process is written as:
ESC option
This example is what appears after entering ESC x (activate execute-extended-command menu)
check to see that you are in the IAP_2010 directory unix by entering the command:
pwd
the result should be (where USERNAME is your own unix username)
/home/USERNAME/IAP_2010/unix
If it is not, you can change to that directory by executing:
cd /home/USERNAME/IAP_2010/unix
create a copy of the file replace.txt with:
cp replace.txt replace2.txt
Begin editing replace2.txt with:
emacs replace2.txt
Note, on new accounts a splash screen welcomes you to emacs use C-l to exit the screen and proceed to editing.
Insert text by regular typing.
Delete letters with C-d
Delete lines with C-k
Find and replace text with ESC x , then type replace-string on M-x line. enter search string, then return, then replacement text.
Move to the end of the document with ESC >
Move back to the start of the document with ESC <
Play tetris with ESC x, tetris
Save and exit with C-x followed by C-c then answer prompts if changes were made.
To turn off the splash welcome screen, edit a file called .emacs to have the contents:
(setq inhibit-splash-screen t)