Course Lessons
Free Trial: 5 lessons remaining
Unlock Full Access
Word Objects: iw, aw, iW, aW
Estimated time: 10 minutes
Task Instructions
Master word and WORD text objects for efficient word manipulation
Practice using word text objects. 'iw' selects the inner word (just the word), 'aw' includes trailing spaces. Capital W versions work with WORDS (including punctuation). Position your cursor anywhere in a word and use ciw to change it.
Learning objectives
- Master inner word (iw) and around word (aw) objects
- Understand the difference between word and WORD
- Practice efficient word deletion and changing
- Learn when to use each variation
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.
ciw
Change inner word
[cd]i[wW]
Use word 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 |
|---|---|
| ciw | Change inner word |
| caw | Change around word (includes spaces) |
| ciW | Change inner WORD (includes punctuation) |
| diw | Delete inner word |
| viw | Select inner word |
Hints
- iw works from anywhere within the word
- aw includes trailing whitespace, useful for removing words
- W (capital) treats special characters as part of the word
# Word Objects Practice
# Use word text objects to fix variable names
def process_user_data():
first_name_string = get_input() # Change to just 'first_name'
last_name_string = get_input() # Change to just 'last_name'
email_address_text = get_input() # Change to just 'email'
# Fix these compound variable names
userAgeInYears = 25 # Change to 'user_age'
isUserActive = True # Change to 'is_active'
maxRetryAttempts = 3 # Change to 'max_retries'
return {
'first': first_name_string,
'last': last_name_string,
'email': email_address_text
}
# TODO: Use text objects to clean up variable names
# 1. Position cursor on 'first_name_string' and use ciw to change it
# 2. Try diw to delete just a word
# 3. Try daw to delete word with spaces
# 4. Use ciW on compound words with underscores