Course Lessons
Free Trial: 5 lessons remaining
Unlock Full Access
Visual Line Mode Mastery
Estimated time: 10 minutes
Task Instructions
Master line-wise selections for working with entire lines and blocks of code
Use Visual Line mode (V) to select entire lines and apply operations. This is perfect for moving functions, deleting blocks of code, or indenting sections. Press V to start line-wise selection, then use j/k to extend the selection.
Learning objectives
- Master visual line mode (V)
- Learn to select multiple lines efficiently
- Practice moving and reorganizing code blocks
- Understand when to use line-wise vs character-wise visual mode
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.
V
Use visual line mode
d
Delete selected lines
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 |
|---|---|
| V | Start visual line mode |
| j/k | Extend selection down/up |
| d | Delete selected lines |
| > | Indent selected lines |
| < | Outdent selected lines |
| : | Execute command on selected lines |
Hints
- Visual Line mode always selects complete lines
- Use V to quickly select and move functions or blocks
- Combine with counts: V4j selects 5 lines total
# Code Organization Challenge
# Use Visual Line mode to reorganize this messy code
def validate_user(user):
# This function is in the wrong place
if user.age < 18:
return False
return True
USER_CONSTANTS = {
'MIN_AGE': 18,
'MAX_NAME_LENGTH': 100
}
def create_user(name, age, email):
# Main user creation logic
user = User()
user.name = name
user.age = age
user.email = email
return user
# TODO: Move validate_user function to be after create_user
# HINT: Position cursor on the validate_user line, press V, then 4j to select the function
# Then use d to delete, move to after create_user, and p to paste