Course
Free Trial: 5 lessons remaining
Unlock Full Access
Practice
Beginner
10 min
The Great Refactor
The Great Refactor: Mastery in Motion
Task Instructions
Apply all your Vim skills to refactor messy legacy code
This is a comprehensive challenge that requires you to use undo, visual mode, and text objects together to clean up legacy code. Take your time, experiment, and use undo when needed.
Learning objectives
- Combine all learned techniques in realistic scenarios
- Practice strategic use of undo during complex edits
- Apply text objects and visual mode together
- Develop professional Vim workflows
Required keystrokes
Your submission is checked for these keystrokes, not just the final text — so reach for the technique, not a workaround.
- [cd]i[w"'()] Use text objects for editing
- u Use undo for safety
Helpful commands
- ciw
- Change inner word
- ci(
- Change inside parentheses
- V
- Visual line mode
- u
- Undo mistakes
- .
- Repeat last change
Stuck? Peek at a hint 4 hints · try it on your own first
- Use ciw to change class/method/variable names
- Use u to undo if you make a mistake
- Use . to repeat similar changes
- Visual mode can help select complex names
# Legacy Code Refactoring Challenge
# This code was written by someone who clearly loves cats but needs better naming
class CatUserManager:
def __init__(self):
self.mr_whiskers_users_list = []
self.princess_fluffybutt_active_sessions = {}
def add_new_mr_whiskers_user(self, user_data):
# Validate the user data first
if not self.validate_princess_fluffybutt_data(user_data):
return False
# Add user to the list
new_user_id = len(self.mr_whiskers_users_list) + 1
user_data['id'] = new_user_id
self.mr_whiskers_users_list.append(user_data)
return True
def validate_princess_fluffybutt_data(self, data):
REQUIRED_FIELDS = ['name', 'email', 'age']
for field in REQUIRED_FIELDS:
if field not in data:
return False
return True
# CHALLENGE: Refactor this code to use professional naming
# Use your full Vim toolkit: text objects, visual mode, and undo for safety
# Goals:
# 1. Rename class to 'UserManager'
# 2. Fix all method names (remove cat references)
# 3. Fix all variable names
# 4. Use undo if you make mistakes!