In this lab, you will edit a file using vim.
| Resources | |
|---|---|
| Machines: | desktopX |
| Files: | /usr/share/doc/vim-common-*/README.txt |
Outcomes
A copy of the vim README.txt
which has been edited according to the instructions in this practice
exercise.
N/A
Log into your desktopX system as student and
open a terminal.
Create a copy of the file
/usr/share/doc/vim-common-*/README.txt in your
home directory.
[student@desktopX ~]$cp /usr/share/doc/vim-common-*/README.txt .
Open /home/student/README.txt in
vim.
[student@desktopX ~]$vim README.txt
Jump to the section titled MAIN AUTHOR, then put your
cursor on the A in AUTHOR.
From command mode, type the following, then press Enter. This will jump to the first occurrence of the text:
/MAIN AUTHOR
Press w to move the cursor one word to the
right; this should put you on the A in
AUTHOR.
Change this occurrence of the word AUTHOR to
ROCKSTAR.
From command mode, type cw to
change the word under the cursor.
Type ROCKSTAR.
Press Esc to return to command mode.
Undo your previous edit.
Press u to undo your last edit.
Redo (i.e., undo your undo) your last edit.
Press Ctrl+r to redo your last undo.
Using visual mode, make a copy of the
INSTALLATION paragraph (including header) and place it
at the end of the file.
Move the cursor to the start of the INSTALLATION
section by searching for ^INSTALLATION. From
command mode, type:
/^INSTALLATION
Enter visual line mode by pressing V.
Move the cursor to the end of section by typing
3}. This will move the cursor three paragraphs down,
selecting our entire section. (The heading counts as a
paragraph.)
Press y to yank (copy) the selected lines to the unnamed buffer.
Move the cursor to the end of the document by pressing G.
Put (paste) the unnamed buffer below the current line by pressing p.
In the entire document, replace each occurrence of README
with PLEASE_READ_ME.
From command mode, type the following:
:%s/README/PLEASE_READ_ME/g
The : enters Ex mode.
% indicates that we want to work on every line
in the document.
s/README/PLEASE_READ_ME/ is the search and
replace command.
The trailing g indicates that this replace
operation can be performed more then once per line.
Exit without saving your changes.
From Command mode type :q!.
The : enters ex mode, the
q indicates we want to quit, and the !
tells vim to force the quit, since we have
unsaved changes.
Clean up by removing your README.txt.
[student@desktopX ~]$rm README.txt