2.3 β€” Line Navigation

2.3 β€” Line Navigation#

Efficient line navigation lets you jump directly to characters within a line. These commands are essential for precise, fast editing.

Line Boundary Commands#

Start and End of Line#

CommandMoves to…
0Column 0 (absolute start)
^First non-blank character
$End of line
g_Last non-blank character

Example line: return result;

    return result;  
^   ^            ^  ^
0   ^            g_ $

When to Use Each#

Find Commands: f, F, t, T#

These are the most powerful line navigation commands.

Find (f and F)#

CommandAction
f{char}Find char forward, cursor on the character
F{char}Find char backward, cursor on the character

Example: function calculate(x, y)

function calculate(x, y)
^cursor

fc β†’ function calculate(x, y)
           ^cursor on 'c'

f( β†’ function calculate(x, y)
                       ^cursor on '('

Till (t and T)#

CommandAction
t{char}Find char forward, cursor before the character
T{char}Find char backward, cursor after the character

Example: function calculate(x, y)

function calculate(x, y)
^cursor

tc β†’ function calculate(x, y)
          ^cursor before 'c'

t( β†’ function calculate(x, y)
                      ^cursor before '('

The Difference Matters for Operators#

The choice between f and t matters when combined with operators:

delete_this_function(args)
^cursor

df( β†’ (args)           # Deletes "delete_this_function("
dt( β†’ delete_this_function(args)   # Deletes "delete_this_function"
                       ^cursor ends here

Repeating Find Commands#

CommandAction
;Repeat last f/F/t/T in same direction
,Repeat last f/F/t/T in opposite direction

Example: Finding all commas in a, b, c, d, e

a, b, c, d, e
^cursor

f,  β†’  a, b, c, d, e
        ^first comma

;   β†’  a, b, c, d, e
              ^second comma

;   β†’  a, b, c, d, e
                 ^third comma

,   β†’  a, b, c, d, e
              ^back to second comma

This is extremely useful for jumping through repeated characters like commas, parentheses, or quotes.

Counts with Find Commands#

All find commands accept counts:

CommandAction
2f,Jump to second comma
3faJump to third β€˜a’
2T"Jump back to second-previous quote

Combining with Operators#

Find commands become incredibly powerful with operators:

Deleting#

CommandAction
df,Delete through comma
dt,Delete up to comma
dF,Delete back through comma
dT,Delete back to comma

Changing#

CommandAction
cf)Change through closing paren
ct"Change up to quote
cT:Change back to colon

Yanking#

CommandAction
yt,Yank up to comma
yf;Yank through semicolon

Practical Examples#

Example 1: Changing a Function Argument#

process(oldValue, secondArg, thirdArg)
        ^cursor

To change oldValue to newValue:

Example 2: Deleting to End of Statement#

let result = calculateSum(a, b);
    ^cursor

To delete everything after result:

Example 3: Navigating Quoted Strings#

message = "Hello, World!"
          ^cursor

To get inside the quotes:

Example 4: Working with Paths#

/home/user/documents/project/file.txt
^cursor

To jump to specific parts:

The | Command: Go to Column#

CommandAction
`{n}`

Example: 42| goes to column 42. Useful for aligning or working with fixed-width data.

Practice Exercises#

Exercise 1: Find Character#

  1. Create line: function processData(input, output, flags)
  2. Press f( to jump to (
  3. Press fo to jump to first o (in β€œoutput”)
  4. Press ; to find next o
  5. Press , to go back

Exercise 2: Till Character#

  1. Create line: let value = "Hello, World!";
  2. Press t= from start β€” where does cursor land?
  3. Press f= from start β€” where does cursor land?
  4. Note the difference

Exercise 3: Delete with Find#

  1. Create: remove, keep, this, text
  2. Position at start
  3. df, β€” deletes β€œremove,”
  4. Undo with u
  5. dt, β€” deletes β€œremove” (keeps comma)

Exercise 4: Multiple Finds#

  1. Create: a, b, c, d, e, f, g
  2. 3f, β€” jump to third comma
  3. ,, (comma twice) β€” go back two commas
  4. ;; β€” go forward two commas

Exercise 5: Combined Editing#

  1. Create: const name = "old value";
  2. Navigate to change β€œold value” using find commands
  3. Try: f"ci" then type new value
  4. This finds quote, then changes inside quotes

Tips for Effective Line Navigation#

Choose the Right Command#

SituationBest Command
Jump to a unique characterf{char}
Delete up to somethingdt{char}
Delete through somethingdf{char}
Navigate repeated charactersf{char} then ;

Think About Delimiters#

Most code has natural delimiters: (, ), ,, ., ", ', :, ;

Learn to jump to these instantly:

Use Count for Speed#

If you see the third comma, don’t do f,;;. Do 3f,.

Summary#

CommandAction
0 / ^ / $Line start / first char / end
f{char}Find forward (on char)
F{char}Find backward (on char)
t{char}Till forward (before char)
T{char}Till backward (after char)
; / ,Repeat find / reverse repeat
`{n}`

Line navigation commands are the key to surgical precision in Vim. Master f, t, and ;, and you’ll edit at the speed of thought.