Vim TaskSet (TwFs)
This set of TwFs (Tasks with Feedback) is for learning Vim.
Describe the common modes in vim.
Normal mode – For navigating and issuing commands.
Insert mode – For editing text.
Visual mode – For selecting blocks of text and issuing associated commands.
Command-line mode – For entering commands like :w, :q, and :s/foo/bar/g.
What is a mode in vim?
A mode is a setting that determines what happens when your press various keys or key combinations.
Example: In normal mode, pressing the “j” key causes the cursor to move down one line. In insert mode, pressing the “j” key inserts the “j” character.
Vim is a modal editor; this means that the the meaning of the keystrokes changes depending on the mode that you are in.
The most common modes in Vim are normal, insert, command, and visual.
List the main things you can do with Vim.
- Work in different modes (Normal, Insert, Visual, Command-line).
- move around efficiently
- edit text
- highlight text (in Visual mode)
- search or search and replace
- explore a directory (using
:Ex
or plugins) - copy, cut (delete), and paste text (using registers)
- undo and redo changes
- save (
:w
) and exit (:q
,:wq
,:q!
) - work with multiple files and buffers
- use tabs and windows to manage multiple views
- record and play macros for repetitive tasks
- file management: create new, delete, search, …
- use registers to store and retrieve text
- customize your environment (key mappings, options, syntax highlighting)
- run shell commands from within Vim
- leverage a vast ecosystem of plugins to extend functionality.
- use powerful text objects and motions for precise editing
- navigate and refer to specific line numbers.
- utilize auto-completion for words and filenames.
Create a file called journal.txt with at least five instances of the word “todo.” Then, replace instances of the whole word “todo” with “TODO:”
Use :%s/\<todo\>/TODO:/g
• :%s → substitute across all lines
• < > → match whole word boundaries
• g → apply change globally on each line
💡 Bonus tip: If you want to confirm each replacement, use c at the end:
:%s/\<todo\>/TODO:/gc
Explain how to color foreground text in vim in the terminal.
In brief, use three ways:
ctermfg=blue
: color namectermfg=123
: ANSI color codectermfg=#FF229A
: hex color code (e.g., #RRGGBB)