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

  1. Lua is King: Neovim’s embedded LuaJIT allows for high-performance configuration and plugins, replacing the slow and obscure Vimscript.
  2. 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.
  3. Modern Plugins: lazy.nvim has revolutionized package management by ensuring plugins are only loaded when needed, keeping startup times under 50ms.
  4. Modular Config: Stop using a single 1000-line .vimrc. Structure your config in lua/user/ modules and require() 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.

  1. Place your cursor over old_name.
  2. Press your rename mapping (e.g., <leader>rn).
  3. Type the new name new_name in 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=4
set shiftwidth=4
set 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.