Introduction to nvim-paredit
nvim-paredit is a precision tool for structural editing of Lisp-family languages (like Clojure) that understands s-expressions. Unlike traditional text editing, it helps you:
- Maintain balanced parentheses/brackets
- Manipulate entire code forms rather than text
- Avoid common paren-mismatch errors
- Navigate and transform nested structures confidently
Integrated into your LunarVim setup with Clojure-specific keybindings, it becomes an extension of your thought process when working with functional code.
Why nvim-paredit in LunarVim?
Your configuration combines LunarVim’s ergonomic defaults with focused Clojure optimizations:
- Space as leader key for memorable combos
- Logical grouping of operations (wrapping, deletion, navigation)
- Native Neovim integration (no GUI dependencies)
- Muscle-friendly Alt-key combinations for common operations
Core Features & Keybindings
Based on your config.lua setup:
1. Installation & Setup
"julienvincent/nvim-paredit",
ft = { "clojure" }, -- Auto-loads only for Clojure files
config = function()
-- Your keybindings here
endAlready configured to activate exclusively for Clojure files.
2. Slurp & Barf Operations
Manipulate element boundaries like a pro:
| Key | Action | Example Transformation |
|---|---|---|
<A-.> | Slurp Forward (absorb next) | (foo) bar → (foo bar) |
<A-,> | Barf Forward (expel last) | (foo bar) → (foo) bar |
<A-[> | Slurp Backward (absorb prev) | foo (bar) → (foo bar) |
<A-]> | Barf Backward (expel first) | (foo bar) → foo (bar) |
Pro Tip: Use Alt+./, with left hand while keeping right hand on home row.
3. Wrapping Operations
| Key | Action | Example |
|---|---|---|
<Space>ww | Wrap element under cursor | foo → (foo) |
<Space>wW | Wrap entire enclosing form | foo (bar) → (foo (bar)) |
4. Deletion Commands
| Key | Action | Example |
|---|---|---|
<Space>dd | Delete entire form | (foo (bar)) → (foo) |
<Space>dk | Delete current element | [1 2 3] → [1 3] |
<Space>di | Delete inside form | (foo bar) → () |
5. Structural Navigation
| Key | Action |
|---|---|
]] | Jump to next element tail |
[[ | Jump to previous element head |
6. Smart Selection
| Key | Action |
|---|---|
vaf | Select Around Form (including parens) |
vif | Select Inside Form (content only) |
Practical Workflow Example
Initial Code:
(defn greet [name]
(str "Hello " name))-
Wrap Parameter Vector
- Place cursor on
[name] <Space>ww→([name])
(Now ready to convert to map destructuring)
- Place cursor on
-
Slurp Function Body
- Place cursor inside
(str ...) <A-.>to absorbname:(defn greet [name] (str "Hello " name))
- Place cursor inside
-
Delete Outer Form
- Place cursor inside
defn <Space>dd→ Removes entire function definition
- Place cursor inside
Advanced Tips
1. Composition is Key
Combine operations like LEGO blocks:
vifto select inner form<Space>wwto wrap selection<A-.>to slurp adjacent elements
2. Navigate While Editing
Use ]]/[[ jumps during refactoring to maintain spatial awareness.
3. Safe Refactoring
All operations maintain structural integrity - no more broken s-exprs!
Troubleshooting
- Alt-key not working? Ensure terminal emulator allows Alt/Meta bindings
- Unexpected behavior? Check paren balance with
%=normal-mode command - Key conflicts? Use
:map <key>to investigate existing mappings
Customization Ideas
Extend your config with:
-- Add square/curly brace wrappers
vim.keymap.set("n", "<leader>w[", function()
paredit.api.wrap_element_under_cursor("[", "]")
end)Conclusion
With your nvim-paredit configuration in LunarVim, you’ve created a Clojure editing environment that:
- Respects Lisp semantics
- Enables fluid code transformation
- Reduces cognitive load through logical keybindings
Your Space-leader based setup ensures commands stay discoverable while keeping hands centered on home row. Combine this with LunarVim’s other features (Space+e file explorer, Space+sk keybinding help) for a full-power Clojure workflow.
Pro Tip: Use :InspectTree on a Clojure file to see the parsed syntax tree that powers these operations!