Bookmark this page

Appendix C. Editing Files with Vim

Guided Exercise: Editing Files with Vim

In this exercise, you will use the Vim tutorial vimtutor that is bundled with the Vim editor to practice basic vim editing techniques.

Outcomes

  • Basic competency with editing text files in the vim text editor, an implementation of vi

  • Knowledge of the vimtutor tutorial for future learning and practice

Open a terminal on the workstation VM.

  1. This exercise will use the existing tutorial program that is bundled with the Vim editor. This tutorial, vimtutor, opens a text file in the vim editor, which provides instructions on how to edit it in order to practice Vim skills. Quitting and re-running vimtutor will provide you with a clean copy of the tutorial.

    Your virtual machine will have at least a basic version of vim installed, but might not have the fully enhanced version of vim which includes the tutorial and help files. Run the command sudo yum install vim-enhanced to make sure that it is installed.

  2. Run vimtutor. Read the Welcome screen and perform Lesson 1.1. Many users of vim only use the keyboard arrow keys for cursor navigation. In vi's early years, users could not rely on working keyboard mappings for arrow keys. Therefore, vi was designed to work using only standard character keys for cursor navigation, the conveniently grouped h, j, k, and l.

    Here is one way to remember them: hang back, jump down, kick up, leap forward.

  3. Return to the vimtutor window. Perform Lesson 1.2. This lesson teaches how to quit vim without saving an unwanted change to your file. All changes are lost, but this can be better than leaving a critical file in an incorrect state.

  4. Return to the vimtutor window. Perform Lesson 1.3.

    Vim has faster, more efficient keystrokes to delete an exact amount of words, lines, sentences, and paragraphs. However, as this exercise demonstrates, any editing job can be accomplished using only x for single-character deletion.

  5. Return to the vimtutor window. Perform Lesson 1.4.

    The minimum required keystrokes to make an edit to an open file includes i to enter edit mode, arrow keys to move the cursor, Backspace to delete, and Esc to exit edit mode. For most edit tasks, the first key pressed is i.

  6. (Optional) Return to the vimtutor window. Perform Lesson 1.5.

    The previous lesson showed the i (insert) command as the keystroke to enter edit mode. This vimtutor lesson demonstrates that other keystrokes are available to change the initial cursor placement when insert mode is entered.

  7. Return to the vimtutor window. Perform Lesson 1.6.

    Save the file by writing and quitting. This completes the minimum set of skills you need to be able to accomplish any text editing task with vim.

  8. Return to the vimtutor window. Finish by reading the Lesson 1 Summary.

    There are six more multi-step lessons in vimtutor. None are assigned as further lessons for this exercise, but feel free to use vimtutor on your own to learn more about Vim.

Revision: do457-2.5-4693601