Course
Free Trial: 5 lessons remaining
Unlock Full Access
Practice
Beginner
10 min
Visual Character Mode Basics
Visual Mode: The Art of Selection
Task Instructions
Practice visual character and word selections to refactor variable names
Use visual character mode to select and change poorly named variables. Position your cursor at the beginning of 'mr_whiskers_connection', press 'v' to enter visual mode, then use motion commands to select the text you want to change. Press 'c' to change the selected text.
Learning objectives
- Master visual character mode (v)
- Practice selecting text with motion commands
- Learn to change selected text efficiently
- Understand the difference between visual modes
Required keystrokes
Your submission is checked for these keystrokes, not just the final text — so reach for the technique, not a workaround.
- v Use visual character mode
- c Change the selected text
Helpful commands
- v
- Start visual character mode
- V
- Start visual line mode
- t{char}
- Move cursor to before character
- f{char}
- Move cursor to character
- c
- Change selected text
Stuck? Peek at a hint 3 hints · try it on your own first
- Try using 'vt_' to select from cursor to before the underscore
- Or use 'viw' to select inner word
- Visual mode highlights the selected text
# Variable Refactoring Challenge
# Your task: Use visual mode to select and change these variable names to something more professional
def initialize_database():
mr_whiskers_connection = Database.connect('localhost') # This connects to the main DB
princess_fluffybutt_timeout = 5000 # Timeout in milliseconds
sir_meows_a_lot_retries = 3 # Number of retry attempts
lady_mittens_buffer_size = 1024 # Buffer size in bytes
return {
'connection': mr_whiskers_connection,
'timeout': princess_fluffybutt_timeout,
'retries': sir_meows_a_lot_retries,
'buffer': lady_mittens_buffer_size
}
# GOAL: Change 'mr_whiskers_connection' to 'db_connection' using visual selection
# HINT: Position cursor on 'm' in 'mr_whiskers_connection', then use 'vt_' to select to underscore