Course Lessons
Free Trial: 5 lessons remaining
Unlock Full Access
Paragraph & Sentence Objects
Estimated time: 10 minutes
Task Instructions
Work with larger text units using paragraph and sentence objects
Use paragraph and sentence text objects for larger text manipulations. Use dap to delete entire paragraphs, cip to rewrite paragraph contents.
Learning objectives
- Master paragraph objects: ip (inner paragraph) and ap (around paragraph)
- Learn sentence objects: is and as
- Practice moving and editing text blocks
- Understand how Vim defines paragraphs and sentences
Required Keystrokes
This lesson requires you to use specific keystrokes to complete it. Your submission will be evaluated based on whether you used the required keystrokes mentioned below, rather than matching a specific output.
[cd]ap
Use paragraph objects
[cdv]i[ps]
Use text objects
What This Means
- Your solution must include the required keystroke patterns
- The order of keystrokes may matter depending on the exercise
- You'll still need to achieve the expected output
- This helps you practice specific Vim techniques
Helpful commands:
| Command | Description |
|---|---|
| dap | Delete a paragraph |
| cip | Change inner paragraph |
| vap | Select around paragraph |
| dis | Delete inner sentence |
| yas | Yank around sentence |
Hints
- Paragraphs are separated by blank lines
- ap includes the blank lines, ip doesn't
- Great for moving functions or text blocks
# Paragraph Objects Practice
# Use paragraph objects to reorganize this code
def old_function():
# This entire function needs to be deleted
print('Delete me!')
x = 1
y = 2
return x + y
def important_function():
# This function stays
result = calculate()
return result
# This comment block
# needs to be completely
# rewritten with better docs
def another_function():
# Implementation here
pass
'''
This is an old docstring
that needs to be updated.
Use cip to rewrite just the content.
'''
# TODO: Practice paragraph objects
# 1. Position cursor in old_function and use dap to delete it
# 2. Use cip to change paragraph contents (keeps blank lines)
# 3. Use cap to change including surrounding blank lines
# 4. Try vap to visually select a paragraph