Vim Modes

15 minutes
  • 2 Learning Objectives

About this Hands-on Lab

In this lab, you’ll be working with Vim Modes. One of the most important things about editing in Vim is knowing what mode you are _in_, how to get _out_ of that mode and back to Command Mode, and then into the next mode you need to operate in.

Being able to use the right mode to accomplish a needed step is critical, and this lab will ensure you know how to get to the right mode for the task.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Start Vim, Lookup Vim Modes in Help, Practice Switching Modes
  1. Start the Vim editor:

    vim
  2. Use Help to lookup information about Vim modes:

    :help modes
  3. Notice this does not show help for the type of modes we are looking for, so try:

    :help vim-modes
  4. Note how many BASIC modes Vim has, and also the help part of the screen is not very large.

  5. To show more of the help screen, press the keystrokes:

    Note: This will not work while using the browser terminal.

    Ctrl-w    (Press and hold Ctrl, then w and release)
    10+       (Type 10 and then Shift-= or +)

    Note: This will increase the size of the Help window and allow you to read more without scrolling

  6. When done reading the descriptions of the seven Basic Modes, exit Help by pressing:

    :q
  7. Verify you are in Command Mode by pressing ESC twice in rapid succession. You should hear the Error Bell, or the screen should flash.

  8. Switch to Insert Mode by pressing the i character, and type a short sentence, such as This is a sentence in Vim. then press the ESC key to return to Command Mode.

    Note that when you are in Insert Mode, the bottom left of your Vim window has the mode shown as -- INSERT --.

  9. With your cursor on the line you have added, and use Visual Line mode to select the line by pressing:

    Shift-v
  10. Change the case of the text in the line with:

    Shift-u
  11. Use Command Line Mode to save your buffer to a file named file1.txt:

    ESC
    :w file1.txt
  12. Then exit Vim with:

    :q

    Note: If while trying to exit from Help, you are presented with a window that appears to contain commands, you pressed q:, so repeat the :q keystrokes until you have exited Help.

    Note: If at any time you are shown a message at the bottom left that Vim is recording @q, simply press the q key again to stop the recording.

Use Help and Command Mode to Create a Working File, Use Visual Mode Select and Manipulate Text, and Use Command Mode to Save and Exit the File
  1. Open the Vim editor:
    vim
  2. Create a working file with:
    :help quotes
    :w ~/quotesdemo.txt
  3. When the file is written to disk (the status will read [converted]), quit Help with:
    :q
  4. While still in Vim, open the ~/quotesdemo.txt file in a buffer with:
    :e ~/quotesdemo.txt
  5. Navigate by your preferred means to the paragraph starting with:
    Coming with a very GUI mindset...
  6. Place your cursor on the first character of the word Coming and press v to start Visual mode. The last line should show -- VISUAL -- as a mode indicator.
  7. Then highlight/select the word Coming by pressing e to go to the end of that word.
  8. Press w twice to select two more words.
  9. Set the words to upper case by pressing U while they are selected.
  10. Enter Visual mode again by pressing:
    Shift-v
  11. Then move your cursor down to select the entire paragraph that starts with Coming and ends with Fonseca).
  12. Set the entire paragraph to upper case by pressing U while all the text is selected.
  13. Re-select the entire paragraph by pressing gv.
  14. Delete the paragraph by pressing d.
  15. Save and exit the file by pressing:
    ZZ

Additional Resources

In order to get used to using Vim, you decide to open up a session and get some more information on the sometimes-confusing modes you have heard about, and practice using the most common ones.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?