To start vi:Example: > vi letter will open a new file called letter to edit, or if letter already exits, open the exiting file. Show
Command Mode vs. Insert ModeInsert mode is the mode to be in when inserting text into the file. Command mode is the mode to be in when giving commands which will move the cursor, delete text, copy and paste, save the file etc. When entering a file, vi is in command mode. To enter text, you must enter insert mode. If in insert mode, enter command mode by hitting the escape, <esc>, key. To insert text:
To move the cursor:You must be in Command Mode to use commands that move the cursor. Each of these commands can be preceded with a Repeat Factor. Examples:
To Delete Text:The d command removes text from the Work Buffer. The amount removed depends on the Repeat Factor and the Unit of Measure you enter after d. If you delete by mistake: give the command u (undo) immediately after you give the delete command. Examples: 3dd will delete 3 lines beginning with the current line.
Viewing Different Parts of the Work Buffer:^Character means that you should hold down the Control key while striking the indicated character key.
Yanking (copy) and Putting (paste) Text:Example:3yy will yank (copy) 3 lines In the following list M is a Unit of Measure that you can precede with a Repeat Factor, n.
Changing TextExample: cw allows you to change a word. The word may be replaced by as many word as needed. Stop the change by hitting < esc >. Ending an Editing Session
Miscellaneous commands
Searching for an expressionWhen in command mode if your enter / the cursor will go to the bottom of the screen. Follow this with an expression and vi will find the next occurrence of that expression in the file. Example: /Bill will find the next occurrence of Bill. If this is followed by the command: n, the next occurrence of Bill is found. Which command will confirm the system directory that you are currently in?To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory. The command pwd stands for print working directory.
What command can be used to display the last five lines of a text file?To look at the last few lines of a file, use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file.
What command is most effective at displaying types of files?The ls command is used to list files.
Can you use shell metacharacters when naming files?It is acceptable to use shell metacharacters when naming files.
|