Vim lessons
Practice
Advanced
10 min
Vim Skills Integration Challenge
Task Instructions
Apply all your Vim skills in a real-world editing scenario
Refactor this code using all your skills: navigate with hjkl/words/lines, use appropriate insert modes, delete unnecessary content, and move code blocks. This simulates real development work.
Learning objectives
- Integrate all Vim skills
- Practice real-world code refactoring
- Build confidence with complex edits
lesson.txt
Start
// Todo List Application function TodoApp() { ·· ·· var todos = [] // CHANGE: to 'const' var completed = [] // CHANGE: to 'const' ···· function addTodo(text) { ········ todos.push({ text: text, done: false }) // SIMPLIFY: text: text ········ } ···· ···· function completeTodo(index) { if (index >= 0 && index < todos.length) { ············ todos[index].done = true ············ completed.push(todos[index]) todos.splice(index, 1) // ADD: semicolon ············ } } ···· // MOVE this function between addTodo and completeTodo function getTodos() { return todos } ···· function clearCompleted() { completed = [] // ADD: semicolon } ···· } Refactor this code using all your Vim skills!
Goal
// Todo List Application function TodoApp() { const todos = []; const completed = []; ···· function addTodo(text) { todos.push({ text, done: false }); } ···· function getTodos() { return todos; } ···· function completeTodo(index) { if (index >= 0 && index < todos.length) { todos[index].done = true; completed.push(todos[index]); todos.splice(index, 1); } } ···· function clearCompleted() { completed = []; } }
Helpful commands
- cw
- Change word
- dd
- Cut line
- p
- Paste after cursor
- >>
- Indent line
- <<
- Unindent line
Stuck? Peek at a hint 3 hints · try it on your own first
- Plan your approach before starting
- Use word navigation for variable name changes
- Remember: dd to cut lines, p to paste them elsewhere
// Todo List Application
function TodoApp() {
var todos = [] // CHANGE: to 'const'
var completed = [] // CHANGE: to 'const'
function addTodo(text) {
todos.push({ text: text, done: false }) // SIMPLIFY: text: text
}
function completeTodo(index) {
if (index >= 0 && index < todos.length) {
todos[index].done = true
completed.push(todos[index])
todos.splice(index, 1) // ADD: semicolon
}
}
// MOVE this function between addTodo and completeTodo
function getTodos() {
return todos
}
function clearCompleted() {
completed = [] // ADD: semicolon
}
}
Refactor this code using all your Vim skills!