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#
| Command | Moves to⦠|
|---|---|
0 | Column 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#
0β When you need column 0, even if itβs whitespace^β When you want the first actual content (most common)$β When you want the absolute end of lineg_β When you want the last actual content (ignoring trailing spaces)
Find Commands: f, F, t, T#
These are the most powerful line navigation commands.
Find (f and F)#
| Command | Action |
|---|---|
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)#
| Command | Action |
|---|---|
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
df(deletes the(itselfdt(deletes up to but not including(
Repeating Find Commands#
| Command | Action |
|---|---|
; | 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:
| Command | Action |
|---|---|
2f, | Jump to second comma |
3fa | Jump to third βaβ |
2T" | Jump back to second-previous quote |
Combining with Operators#
Find commands become incredibly powerful with operators:
Deleting#
| Command | Action |
|---|---|
df, | Delete through comma |
dt, | Delete up to comma |
dF, | Delete back through comma |
dT, | Delete back to comma |
Changing#
| Command | Action |
|---|---|
cf) | Change through closing paren |
ct" | Change up to quote |
cT: | Change back to colon |
Yanking#
| Command | Action |
|---|---|
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:
ct,then typenewValue
Example 2: Deleting to End of Statement#
let result = calculateSum(a, b);
^cursor
To delete everything after result:
f=thenD(delete to end of line)- OR
dt;thenxto also remove the semicolon
Example 3: Navigating Quoted Strings#
message = "Hello, World!"
^cursor
To get inside the quotes:
f"to go to first quotelto move inside- OR
f"lor better:f"thenci"to change inside
Example 4: Working with Paths#
/home/user/documents/project/file.txt
^cursor
To jump to specific parts:
f/;;β jump to third/(documents)t.β jump to just before the.f.lβ jump to the extension (txt)
The | Command: Go to Column#
| Command | Action |
|---|---|
| `{n} | ` |
Example: 42| goes to column 42. Useful for aligning or working with fixed-width data.
Practice Exercises#
Exercise 1: Find Character#
- Create line:
function processData(input, output, flags) - Press
f(to jump to( - Press
foto jump to firsto(in βoutputβ) - Press
;to find nexto - Press
,to go back
Exercise 2: Till Character#
- Create line:
let value = "Hello, World!"; - Press
t=from start β where does cursor land? - Press
f=from start β where does cursor land? - Note the difference
Exercise 3: Delete with Find#
- Create:
remove, keep, this, text - Position at start
df,β deletes βremove,β- Undo with
u dt,β deletes βremoveβ (keeps comma)
Exercise 4: Multiple Finds#
- Create:
a, b, c, d, e, f, g 3f,β jump to third comma,,(comma twice) β go back two commas;;β go forward two commas
Exercise 5: Combined Editing#
- Create:
const name = "old value"; - Navigate to change βold valueβ using find commands
- Try:
f"ci"then type new value - This finds quote, then changes inside quotes
Tips for Effective Line Navigation#
Choose the Right Command#
| Situation | Best Command |
|---|---|
| Jump to a unique character | f{char} |
| Delete up to something | dt{char} |
| Delete through something | df{char} |
| Navigate repeated characters | f{char} then ; |
Think About Delimiters#
Most code has natural delimiters: (, ), ,, ., ", ', :, ;
Learn to jump to these instantly:
f(β function callf"β string startf.β method chainf,β next argument
Use Count for Speed#
If you see the third comma, donβt do f,;;. Do 3f,.
Summary#
| Command | Action |
|---|---|
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.