Moving the Cursor by Linda Lamb, Elbert Hannah, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Moving the Cursor

You may spend only a small amount of time in an editing session adding new text in insert mode; much of the time you will be making edits to existing text.

In command mode you can position the cursor anywhere in the file. Since you begin all basic edits (changing, deleting, and copying text) by placing the cursor at the text that you want to change, you want to be able to move the cursor to that place as quickly as possible.

There are vi commands to move the cursor:

  • Up, down, left, or right—one character at a time

  • Forward or backward by blocks of text such as words, sentences, or paragraphs

  • Forward or backward through a file, one screen at a time

In Figure 2-1, an underscore marks the present cursor position. Circles show movement of the cursor from its current position to the position that would result from various vi commands.

Sample movement commands
Figure 2-1. Sample movement commands

Single Movements

The keys h, j, k, and l, right under your fingertips, will move the cursor:

h

Left, one space

j

Down, one line

k

Up, one line

l

Right, one space

You can also use the cursor arrow keys (, , , ), + and - to go up and down, or the ENTER and BACKSPACE keys, but they are out of the way. At first, it may seem awkward to use letter keys instead of arrows for cursor movement. After a short while, though, you’ll find it is one of the things you’ll like best about vi—you can move around without ever taking ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required