Screen Too Small

This course material requires a larger screen to properly display the terminal and editor interfaces.

Please use a tablet, laptop, or desktop computer for the best learning experience.

You can continue browsing, but the experience will be significantly limited.

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

 1// Todo List Application
 2
 3function TodoApp() {
 4··
 5··
 6    var todos = []  // CHANGE: to 'const'
 7    var completed = []  // CHANGE: to 'const'
 8····
 9    function addTodo(text) {
10········
11        todos.push({ text: text, done: false })  // SIMPLIFY: text: text
12········
13    }
14····
15····
16    function completeTodo(index) {
17        if (index >= 0 && index < todos.length) {
18············
19            todos[index].done = true
20············
21            completed.push(todos[index])
22            todos.splice(index, 1)  // ADD: semicolon
23············
24        }
25    }
26····
27    // MOVE this function between addTodo and completeTodo
28    function getTodos() {
29        return todos
30    }
31····
32    function clearCompleted() {
33        completed = []  // ADD: semicolon
34    }
35····
36}
37
38Refactor this code using all your Vim skills!

Goal

 1// Todo List Application
 2
 3function TodoApp() {
 4    const todos = [];
 5    const completed = [];
 6····
 7    function addTodo(text) {
 8        todos.push({ text, done: false });
 9    }
10····
11    function getTodos() {
12        return todos;
13    }
14····
15    function completeTodo(index) {
16        if (index >= 0 && index < todos.length) {
17            todos[index].done = true;
18            completed.push(todos[index]);
19            todos.splice(index, 1);
20        }
21    }
22····
23    function clearCompleted() {
24        completed = [];
25    }
26}

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
vim@sandbox: ~/workspace
Save your file with :w ⏎ to unlock Submit