-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcode-preview.txt
More file actions
243 lines (201 loc) · 10.7 KB
/
Copy pathcode-preview.txt
File metadata and controls
243 lines (201 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
*code-preview.txt* Review AI coding-agent edits as native Neovim diffs
==============================================================================
CONTENTS *code-preview-contents*
1. Introduction ........................... |code-preview-introduction|
2. Setup .................................. |code-preview-setup|
3. Configuration .......................... |code-preview-config|
4. Commands ............................... |code-preview-commands|
5. Keymaps ................................ |code-preview-keymaps|
6. Agents ................................. |code-preview-agents|
==============================================================================
1. INTRODUCTION *code-preview-introduction*
*code-preview*
code-preview.nvim shows the edits an AI coding agent proposes as native Neovim
diffs, so you review, accept, or reject changes inside your editor instead of
eyeballing them in the agent's CLI.
It supports four agents as equal first-class citizens — Claude Code, OpenCode,
GitHub Copilot CLI, and OpenAI Codex CLI — on macOS, Linux, and Windows.
The README is the landing page; this help file is the reference manual. The
configuration block in |code-preview-config| is the canonical option reference
and is kept in sync with the defaults in `lua/code-preview/init.lua`.
==============================================================================
2. SETUP *code-preview-setup*
*code-preview.setup()*
Call `setup()` once from your plugin config. It works with zero arguments;
pass a table to override any default (see |code-preview-config|). Options are
deep-merged over the defaults.
>lua
require("code-preview").setup()
<
With lazy.nvim: >lua
{
"Cannon07/code-preview.nvim",
config = function()
require("code-preview").setup()
end,
}
<
After `setup()`, install the hooks for your agent (see |code-preview-agents|)
and restart that agent's CLI.
==============================================================================
3. CONFIGURATION *code-preview-config*
Full default configuration. These values are copied verbatim from
`lua/code-preview/init.lua` and are the source of truth for every option: >lua
require("code-preview").setup({
debug = false, -- enable debug logging to stdpath("log")/code-preview.log
diff = {
layout = "tab", -- "tab", "vsplit", or "inline"
layouts = {}, -- override layout per backend: { opencode = "tab", codex = "vsplit" }
labels = { current = "CURRENT", proposed = "PROPOSED" },
equalize = true,
full_file = true,
visible_only = false, -- only show diffs for files open in a visible nvim window
defer_claude_permissions = false, -- when true, skip permissionDecision and let Claude Code's own settings decide
},
neo_tree = {
enabled = true,
-- reveal = false disables scroll-to-file in the tree. Change indicators
-- (modified/created/deleted icons) still appear — to disable those too,
-- set neo_tree.enabled = false.
reveal = true, -- reveal edited files in neo-tree
reveal_root = "cwd", -- "cwd" (default) or "git" (nearest git root)
refresh_on_change = true,
position = "right",
symbols = {
modified = "",
created = "",
deleted = "",
},
highlights = {
modified = { fg = "#e8a838", bold = true },
created = { fg = "#56c8d8", bold = true },
deleted = { fg = "#e06c75", bold = true, strikethrough = true },
},
},
keys = {
-- Set any entry to false to skip that binding. Set `keys = false` to skip all.
-- <Plug>(CodePreviewCloseAll) is always defined so users can map it themselves.
next_change = "]c", -- buffer-local in inline diff buffers
prev_change = "[c", -- buffer-local in inline diff buffers
close_all = "<leader>dq", -- global; close diff and clear indicators
},
highlights = {
current = {
DiffAdd = { bg = "#4c2e2e" },
DiffDelete = { bg = "#4c2e2e" },
DiffChange = { bg = "#4c3a2e" },
DiffText = { bg = "#5c3030" },
},
proposed = {
DiffAdd = { bg = "#2e4c2e" },
DiffDelete = { bg = "#4c2e2e" },
DiffChange = { bg = "#2e3c4c" },
DiffText = { bg = "#3e5c3e" },
},
inline = {
added = { bg = "#2e4c2e" },
removed = { bg = "#4c2e2e" },
added_text = { bg = "#3a6e3a" },
removed_text = { bg = "#6e3a3a" },
},
},
})
<
Option notes ~
*code-preview-config-layout*
diff.layout "tab" (default) | "vsplit" | "inline". Selects how a
preview is rendered. "tab" and "vsplit" use the
side-by-side renderer; "inline" uses the unified-diff
renderer (with `]c`/`[c` navigation).
*code-preview-config-layouts*
diff.layouts Per-agent layout override, keyed by agent id:
`claudecode`, `opencode`, `copilot`, `codex`. Any agent
not listed falls back to `diff.layout`.
Example: `layouts = { codex = "inline" }`.
diff.visible_only When true, suppress previews for files not visible in any
Neovim window. Change indicators still fire. Toggle at
runtime with `:CodePreviewToggleVisibleOnly`.
diff.defer_claude_permissions
Claude Code only. When true, the plugin does not force a
review gate and defers to Claude Code's own permission
settings.
neo_tree Soft dependency. If neo-tree is not installed these
options are inert. `enabled = false` disables the
integration entirely; `reveal = false` keeps the change
indicators but stops scrolling the tree to the file.
keys Set any entry to false to skip that binding, or
`keys = false` to skip them all. `<Plug>(CodePreviewCloseAll)`
is always defined so it can be mapped manually: >lua
vim.keymap.set("n", "<leader>x",
"<Plug>(CodePreviewCloseAll)")
<
==============================================================================
4. COMMANDS *code-preview-commands*
*:CodePreviewInstallClaudeCodeHooks*
:CodePreviewInstallClaudeCodeHooks
Install Claude Code hooks to `.claude/settings.local.json`.
*:CodePreviewUninstallClaudeCodeHooks*
:CodePreviewUninstallClaudeCodeHooks
Remove Claude Code hooks (leaves other hooks intact).
*:CodePreviewInstallOpenCodeHooks*
:CodePreviewInstallOpenCodeHooks
Install the OpenCode plugin to `.opencode/plugins/`.
*:CodePreviewUninstallOpenCodeHooks*
:CodePreviewUninstallOpenCodeHooks
Remove the OpenCode plugin.
*:CodePreviewInstallCopilotCliHooks*
:CodePreviewInstallCopilotCliHooks
Install Copilot CLI hooks to
`.github/hooks/code-preview.json`.
*:CodePreviewUninstallCopilotCliHooks*
:CodePreviewUninstallCopilotCliHooks
Remove Copilot CLI hooks.
*:CodePreviewInstallCodexCliHooks*
:CodePreviewInstallCodexCliHooks
Install Codex CLI hooks to `.codex/hooks.json`.
*:CodePreviewUninstallCodexCliHooks*
:CodePreviewUninstallCodexCliHooks
Remove Codex CLI hooks.
*:CodePreviewCloseDiff*
:CodePreviewCloseDiff
Manually close the diff. Use after rejecting a change.
*:CodePreviewStatus*
:CodePreviewStatus
Show socket path, hook status, and a dependency check.
*:CodePreviewToggleVisibleOnly*
:CodePreviewToggleVisibleOnly
Toggle `diff.visible_only` — show diffs only for files
open in a visible window.
*:checkhealth-code-preview*
:checkhealth code-preview
Full health check across all agents.
==============================================================================
5. KEYMAPS *code-preview-keymaps*
Defaults (all configurable via the `keys` table, see |code-preview-config|):
<leader>dq global Close the diff and clear indicators
(same as `:CodePreviewCloseDiff`).
]c inline diff buffer Jump to the next change.
[c inline diff buffer Jump to the previous change.
*<Plug>(CodePreviewCloseAll)*
A `<Plug>(CodePreviewCloseAll)` mapping is always defined, regardless of the
`keys` config, so it can be bound manually even with `keys = false`.
==============================================================================
6. AGENTS *code-preview-agents*
After |code-preview.setup()|, install hooks for your agent and restart its
CLI. The diff/review experience is identical across agents.
Claude Code ~
`:CodePreviewInstallClaudeCodeHooks`. No extra agent config required.
OpenCode ~
`:CodePreviewInstallOpenCodeHooks`, then enable permission prompts in
`~/.config/opencode/opencode.json`:
`{ "permission": { "edit": "ask", "bash": "ask" } }`.
GitHub Copilot CLI ~
`:CodePreviewInstallCopilotCliHooks`. No extra agent config required.
OpenAI Codex CLI ~
`:CodePreviewInstallCodexCliHooks`, then make Codex ask before applying
edits in `.codex/config.toml` (or `~/.codex/config.toml`):
`approval_policy = "on-request"` and `sandbox_mode = "read-only"`.
Hooks are enabled by default in modern Codex.
For architecture and internals, see CONTRIBUTING.md and CONTEXT.md in the
repository root.
vim:tw=78:ts=8:sw=8:noet:ft=help:norl: