Vim Tasks with Feedback (TwFs)
This set of TwFs (Tasks with Feedback) is for learning Vim.
Go to Linear ViewDescribe 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.
id: 1744109546
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.
id: 1744804063
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.
id: 1744113373
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
id: 1744106744
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)
id: 1744750826
How can you delete all open buffers in Vim?
Use the command:
:bufdo bd
id: 1753626474
What is a keybinding?
A keybinding is mapping between a key stroke and one or more commands.
For example, you can map a key stroke to open a file that you commonly use.
id: 1753877114
How do you set a keybinding in Vim using Lua?
Syntax
mode: The mode for the keybinding (e.g., ‘n’ for normal, ‘i’ for insert).
keys: The key combination to trigger the command.
command: The Vim command or Lua function to run.
explanation: Documentation of the keymap (optional)
Example and Details
Add the keybinding to either:
~/.config/nvim/init.lua — for a single-file config, or
~/.config/nvim/lua/keybindings.lua — if you organize configs by module.
Example keybinding:
vim.keymap.set('n', '<leader>cd', ':cd /Users/donaldelger/Documents/Vault/Notes<CR>')
-- Change directory to Notes
Explanation
‘n’: This binding works in normal mode.
‘
cd’: The shortcut you press (by default, unless you’ve changed your ). :cd /Users/donaldelger/Documents/Vault/Notes<CR>
: Runs the Vim :cd command to change the current directory.<CR>
simulates pressing Enter.
This lets you quickly switch to your Vault Notes directory by pressing in normal mode.
id: 1753877303