Module Review: Modern Vim
[!NOTE] This module explores the core principles of Module Review: Modern Vim, deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.
Consolidate your learning of the modern Neovim ecosystem and prepare for advanced configuration.
1. Key Takeaways
- Lua is King: Neovim’s embedded LuaJIT allows for high-performance configuration and plugins, replacing the slow and obscure Vimscript.
- Built-in LSP: You don’t need heavy plugins for IDE features anymore. Neovim’s native LSP client communicates directly with language servers for definition, hover, and diagnostics.
- Modern Plugins:
lazy.nvimhas revolutionized package management by ensuring plugins are only loaded when needed, keeping startup times under 50ms. - Modular Config: Stop using a single 1000-line
.vimrc. Structure your config inlua/user/modules andrequire()them.
2. Interactive Flashcards
Test your recall of the key concepts covered in this module. Click a card to flip it.
3. Workflow Demo: LSP Refactoring
Here is a common scenario: renaming a variable across your entire project. In traditional Vim, this might require complex sed commands or cdo. With modern Neovim and LSP, it’s a single keystroke sequence.
Scenario: You want to rename the variable old_name to new_name.
- Place your cursor over
old_name. - Press your rename mapping (e.g.,
<leader>rn). - Type the new name
new_namein the floating prompt and press<Enter>.
Before:
local old_name = "example"
print(old_name)
After:
local new_name = "example"
print(new_name)
4. Interactive Practice: Vimscript to Lua
Practice converting standard Vimscript options to their Lua equivalents using the vim.opt table.
Practice: Translate this Vimscript to Lua
set tabstop=4set shiftwidth=4set expandtab
5. Cheat Sheet
| Action | Lua Command | Description |
|---|---|---|
| Set Option | vim.opt.number = true |
Enable line numbers |
| Unset Option | vim.opt.wrap = false |
Disable line wrapping |
| Set Variable | vim.g.mapleader = " " |
Set global variable (leader key) |
| Map Key | vim.keymap.set('n', 'lhs', 'rhs') |
Create a key mapping in normal mode |
| Install Plugin | lazy.setup({ "user/repo" }) |
Add a plugin via lazy.nvim |
| LSP Hover | vim.lsp.buf.hover() |
Show documentation for symbol |
| LSP Definition | vim.lsp.buf.definition() |
Go to definition |
| LSP Rename | vim.lsp.buf.rename() |
Rename symbol across project |
| Format | vim.lsp.buf.format() |
Format current buffer |
| Diagnostics | vim.diagnostic.open_float() |
Show error details in popup |
6. Glossary
For a full list of terms, visit the Vim Glossary.
7. Next Steps
You have mastered the modern Neovim stack.
- Practice: Port your old
.vimrctoinit.lua. - Explore: Check out Awesome Neovim for more plugins.
- Advance: Move on to Module 06: Workspace Management to learn about sessions, terminals, and project navigation.