- Lab
- A Cloud Guru
Manipulating Text in Vim
Editing text, in a precise, specific, and efficient manner is the hallmark of a good system administrator, developer or anyone who works with text on a daily basis. Being able to get done what needs doing in the most direct and time-saving way is a wonderful skill to possess. In this hands-on lab, you will gain valuable practice in inserting, copying, pasting, selecting, deleting, changing, and altering text. You also be using undo and redo to bring your text-editing skills up the next level.
Path Info
Table of Contents
-
Challenge
Insert and Append Text and Lines, Yank and Paste Text and Lines, Then Delete Text and Lines
- Open the Vim editor:
vim
- Create a working file (and open it for editing) with:
:help :w ~/vimhelp.txt :q :e ~/vimhelp.txt
- Go to the top of the file with
gg
and then navigate to the line that starts with this text:Get out of Vim
- Press
o
to add a line under the current line. - On that line, add the following text, taking care to line up the
:
with the other instances of:
on other lines:ATTENTION: Do NOT Use killall -9 vim to Exit Vim!
- When added, hit the
ESC
key to return to Command Mode. Use^
to go back to the front of the wordATTENTION
, then0
(zero) to go to the very beginning of the line. - Next, place the cursor on the empty line between your current line and the one that reads
Jump to a subject
, and delete the empty line by pressingdd
. - Now copy the
ATTENTION
line by moving to it and pressingyy
. - Go to line that starts with
Jump Back
and usep
to paste the copied line below it. - Then place your cursor on the blank line, in between the current line and the one that begins with
Get specific help
, and press theyy
keys to copy the blank line. - Then create a blank line by pressing
P
. - Now insert a range of numbers automatically using:
:put =range(1,10)
- Open the Vim editor:
-
Challenge
Visually Select Text and Lines, Change, Replace and Alter Text, and Use Undo and Redo
Note: You must have completed the steps in Task 1 in order to do Task 2.
- Position your cursor on the
4
in the list of newly added numbers, and copy and paste that line with:yy p
- With your cursor on the bottom-most
4
, select from there to the number10
using:Ctrl-v Down Arrow (Make sure to select the 0 in 10 too)
- Now increment those numbers with
Ctrl-a
so that the4
your cursor is on increments to5
, and the list now ends with11
. - Move your cursor to the numeral
1
on the first line of the eleven numbered lines. - Select lines numbered 1-9 by pressing:
Ctrl-v 8j
- Add a leading zero to the lines numbered
1
through9
with:Shift-i (aka I) 0 ESC
- Re-select the nine lines by pressing
gv
. - Extend the selected area to include all eleven numbered lines, all numbers. (The cursor should be blinking on the last 1 in 11.)
- With all eleven lines and all numerals selected, add the same text to all eleven lines with:
Shift-a (aka A) Space This will be 11 numbered lines followed by this text. ESC
- Now navigate to the line that begins with:
Get Specific Help...
- Position your cursor on the
s
ofspecific
and change the word to beparticular
using:ESC cw particular ESC
- Now join that line and the line below it into a long paragraph with by pressing
J
. - Move your cursor to the end of the line, with the
$
character. Your cursor should be on the.
aftercommand
. - Now that you have done a number of changes, use the
u
key to undo several of your changes, the use3u
to undo 3 more changes. Continue to useu
until you receive the message:Already at oldest change
- Then use
Ctrl-r
to redo your changes until you receive the message:Already at newest change
- Quit your
vimhelp.txt
file, saving your changes by pressing:ESC ESC :x
- Position your cursor on the
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.