Course Lessons
Free Trial: 5 lessons remaining
Unlock Full Access
Visual Block Magic
Estimated time: 10 minutes
Task Instructions
Use visual block mode to efficiently refactor multiple variable names at once
Use visual block mode to select text across multiple lines in a column. Position your cursor at the start of the text you want to select, press Ctrl+v to enter visual block mode, then use j/k to move down/up and h/l to extend the selection. Press c to change the selected block.
Learning objectives
- Master visual block mode (Ctrl+v)
- Understand multi-line column selections
- Practice extending selections in block mode
- Learn to change multiple lines simultaneously
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.
<C-v>
Use visual block mode
c
Change the selected block
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 |
|---|---|
| Ctrl+v | Start visual block mode |
| j/k | Move down/up in block mode |
| h/l | Extend selection left/right |
| I | Insert at beginning of block |
| A | Append at end of block |
| c | Change selected block |
Hints
- Position cursor at start of 'mr_whiskers_database', press Ctrl+v
- Move down 4 lines with 4j, extend right to select the text
- Press c to change the selected block
# Multi-line Variable Refactoring Challenge
# These variables are aligned but need better names...
mr_whiskers_database_host = 'localhost'
mr_whiskers_database_port = 5432
mr_whiskers_database_name = 'production'
mr_whiskers_database_user = 'admin'
mr_whiskers_database_password = 'secret123'
princess_fluffybutt_api_url = 'https://api.example.com'
princess_fluffybutt_api_key = 'abc123xyz'
princess_fluffybutt_api_timeout = 30
# TASK: Use visual block mode to select 'mr_whiskers_database' from all 5 lines
# and replace it with 'db' to make: db_host, db_port, db_name, db_user, db_password
# HINT: Ctrl+v starts visual block mode, then move down with j and select with motion keys