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

Navigating in Vim

Being able to quickly and accurately move to where you need to be in Vim is an important skill, and one that only takes a little practice before you'll be zooming to right where you need to be! In this hands-on lab, we will start with the basics of moving around in a buffer or file's contents, getting to top/bottom, directly to a given line, or move around in large movements such as by screen or buffer. We'll then move around by paragraph, on a line, and even down to moving around word by word, both forward and backward for all movements.

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

    Move Around in Vim, Change the Cursor Line Positioning, and Navigate to the Buffer Boundaries

    1. Open the Vim editor:

      vim
      
    2. Create a working file:

      :help quotes
      
      :w ~/quotesdemo.txt
      
    3. When the file is written to disk, quit Help:

      :q
      
    4. Open the ~/quotesdemo.txt file in a buffer:

      :e ~/quotesdemo.txt
      
    5. Navigate to the top of the file:

      gg
      
    6. Navigate to the end of the file to see how many lines long it is:

      G
      

      Note: Pressing Ctrl+G will also display the number of lines in a buffer/file.

    7. Navigate to line 100 of the file:

      100G
      
    8. Noting the percentage shown on the far lower right of the screen, navigate to 50% of the way down the file:

      50%
      
    9. To see if the top line of the screen is the start of a paragraph, press H and then k to move to the top line and move the display up one line.

      Note: If the cursor won't go to the top of the screen, use the following to turn OFF the scrolloff option:

      :set scrolloff=0
      
    10. Reposition your cursor to the middle line of the screen by pressing M, then to the bottom line of the screen with L.

    11. Navigate to line 17:

      17G
      
    12. Press O (upper-case "o") to open a new line above the one that begins:

      Coming with a very GUI mindset...
      
    13. While in Insert Mode, try the various navigation commands you have tried so far, then use the dedicated PgUp, PgDn, Home, End and cursor keys, which is all Insert Mode really allows for navigation.

    14. Quit the demonstration file without saving changes:

      ESC
      
      :q!
      
  2. Challenge

    Affect Line Display, Show the Control Characters in Your Files, Navigate on Lines and by Words and Characters

    1. Edit the demonstration file you created in Task 1:

      vim ~/quotesdemo.txt
      
    2. Navigate to the top of the file:

      gg
      
    3. Turn on the line numbers option:

      :set number
      
    4. Navigate to the first line of the fourth paragraph:

      }}}}j
      
    5. Your cursor should be on the first character of the line that begins:

      Vim is so much better than vi...
      
    6. Now move your cursor to the end of the line by pressing the $ character.

      Note: Normally the end of a line and the end of a paragraph are the same thing, as a paragraph usually is a sentence or more ending in a Line Feed.

    7. Note that you are not going to the closing parantheses following the word Australia, as you would expect to. Look at the line numbers for a clue.

    8. Set the displaying of un-printable characters on the screen:

      :set list
      
    9. Note that the $ or LF (Line Feed) character is at the end of each of the lines, indicating the use of a manual ENTER to set the length of the line. This and line numbers tell the whole story.

    10. Place your cursor on the top line of the paragraph that begins with:

      Coming with a very GUI mindset....
      
    11. Turn the multiple physical lines in the paragraph into a proper paragraph by pressing the J character until there are no remaining $ characters in between Coming with and (Jose Fonseca).

    12. Now use the $ character to go to the end of the "line" you have just created out of five individual lines, then press the ^ character to go to the beginning of the new paragraph/line.

    13. Use the w character to move forward through the paragraph for 10 words, noticing how it treats punctuation as a word. Then use 5w to move forward five words at a time.

    14. Navigate backwards to the beginning of the paragraph using B, noticing how it treats the punctuation.

    15. Look up why this happens:

      :help B
      
    16. Make sure to read the definitions of what a word and a WORD are and the difference. Also note similar information about b, w, and W.

    17. Exit Help:

      :q
      
    18. Position your cursor at the beginning of the paragraph that starts with Coming with a very GUI.... and then use e to move to the end of the word, then several more, until you reach punctuation, noting where it stops, then use ^ to then repeat those steps with E, noting the (subtle) difference that makes.

    19. Return to the top of the file:

      [[
      
    20. Quit and don't save the demonstration file:

      :q!
      

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