Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Apr 03, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Insert and Append Text and Lines, Yank and Paste Text and Lines, Then Delete Text and Lines

    1. Open the Vim editor:
      vim
      
    2. Create a working file (and open it for editing) with:
      :help
      :w ~/vimhelp.txt
      :q
      :e ~/vimhelp.txt
      
    3. Go to the top of the file with gg and then navigate to the line that starts with this text:
      Get out of Vim
      
    4. Press o to add a line under the current line.
    5. 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!
      
    6. When added, hit the ESC key to return to Command Mode. Use ^ to go back to the front of the word ATTENTION, then 0 (zero) to go to the very beginning of the line.
    7. 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 pressing dd.
    8. Now copy the ATTENTION line by moving to it and pressing yy.
    9. Go to line that starts with Jump Back and use p to paste the copied line below it.
    10. Then place your cursor on the blank line, in between the current line and the one that begins with Get specific help, and press the yy keys to copy the blank line.
    11. Then create a blank line by pressing P.
    12. Now insert a range of numbers automatically using: :put =range(1,10)
  2. 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.

    1. Position your cursor on the 4 in the list of newly added numbers, and copy and paste that line with:
      yy
      p
      
    2. With your cursor on the bottom-most 4, select from there to the number 10 using:
      Ctrl-v
      Down Arrow   (Make sure to select the 0 in 10 too)
      
    3. Now increment those numbers with Ctrl-a so that the 4 your cursor is on increments to 5, and the list now ends with 11.
    4. Move your cursor to the numeral 1 on the first line of the eleven numbered lines.
    5. Select lines numbered 1-9 by pressing:
      Ctrl-v
      8j
      
    6. Add a leading zero to the lines numbered 1 through 9 with:
      Shift-i     (aka I)
      0
      ESC
      
    7. Re-select the nine lines by pressing gv.
    8. Extend the selected area to include all eleven numbered lines, all numbers. (The cursor should be blinking on the last 1 in 11.)
    9. 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
      
    10. Now navigate to the line that begins with:
      Get Specific Help...
      
    11. Position your cursor on the s of specific and change the word to be particular using:
      ESC
      cw
      particular
      ESC
      
    12. Now join that line and the line below it into a long paragraph with by pressing J.
    13. Move your cursor to the end of the line, with the $ character. Your cursor should be on the . after command.
    14. Now that you have done a number of changes, use the u key to undo several of your changes, the use 3u to undo 3 more changes. Continue to use u until you receive the message: Already at oldest change
    15. Then use Ctrl-r to redo your changes until you receive the message: Already at newest change
    16. Quit your vimhelp.txt file, saving your changes by pressing: ESC ESC :x

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans