Chapter 3. Moving Around in a Hurry

You will not, of course, just create new files. You’ll spend a lot of your time editing existing files. You rarely want to simply open to the first line in the file and move through it line by line; you sometimes want to get to a specific place in a file and start working.

All edits start with you moving the cursor to where you want to begin the edit (or, with ex line editor commands, by identifying the line numbers to be edited). This chapter shows you how to think about movement in a variety of ways (by screens, by text, by patterns, or by line numbers). There are many ways to move around in vi and Vim, since editing speed depends on getting to your destination with only a few keystrokes.

This chapter covers:

  • Movement by screens

  • Movement by text blocks

  • Movement by searches for patterns

  • Movement by line number

Movement by Screens

When you read a book, you think of “places” in the book in terms of pages: the page where you stopped reading, or the page number in an index. You don’t have this convenience when you’re editing files. Some files take up only a few lines, and you can see the whole file at once. But many files have hundreds (or thousands!) of lines.

You can think of a file as text on a long roll of paper. The screen is a window of (often) 24 lines of text on that long roll.1

In insert mode, as you fill up the screen with text, you will end up typing on the bottom line of the screen. When you reach the end and press ENTER ...

Get Learning the vi and Vim Editors, 8th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.