ChatGPT NeoVim Plugin (Extensively Updated with Step-by-Step Prompting and Diff-Based Changes)
This plugin integrates a ChatGPT O1 model workflow into Neovim. It allows you to:
-
Generate prompts containing:
- An initial prompt (from
.chatgpt_config.yaml) - A list of directories (also specified in
.chatgpt_config.yaml) from which it gathers the project structure and file contents - Interactive file selection if enabled, so you can pick exactly which directories to include
- Any initial files you define (e.g.,
README.md, etc.)
- An initial prompt (from
-
Copy these prompts to your clipboard to paste into ChatGPT O1.
-
Receive YAML changes from ChatGPT that include diffs, then run
:ChatGPTPasteto apply them or supply additional files.- If you’re updating an existing file, provide a
difffield in the YAML. - If you’re creating a new file, use the
contentfield. - If you’re deleting a file, use
delete: true.
- If you’re updating an existing file, provide a
New Key Features
-
Step-by-Step Prompting (
enable_step_by_step: true):
If the request grows too large (exceedstoken_limit), the plugin automatically generates a special prompt asking the model to split the task into smaller steps, working through them one by one. -
Partial Acceptance: If
partial_acceptance: true, you can open a buffer that lists final diffs or file creations. You can remove or comment out lines you don’t want, then only those changes are applied. -
Preview Changes: If
preview_changes: true, you get a buffer showing proposed diffs or new file content before you apply them. -
Interactive File Selection: If
interactive_file_selection: true, you choose which directories from.chatgpt_config.yamlget included in the prompt, reducing token usage. -
Improved Debug: If
improved_debug: true, debug logs go into a dedicatedChatGPT_Debug_Logbuffer for easier reading. -
Diff-Based Changes: Rather than supplying entire file content for edits, you can include a
diffin the YAML response. This allows you to see exactly what changed line by line and accept or reject it.
Example .chatgpt_config.yaml
project_name: "chatgpt_nvim"
default_prompt_blocks:
- "basic-prompt"
- "workflow-prompt"
directories:
- "."
initial_files:
- "README.md"
debug: false
enable_step_by_step: true
preview_changes: true
interactive_file_selection: true
partial_acceptance: true
improved_debug: true
token_limit: 3000
Usage
-
:ChatGPT- If
interactive_file_selectionis on, you’ll pick directories to include in a buffer namedChatGPT_File_Selection. - Save & close with
:wq,:x, or:bd. - If
enable_step_by_stepis on and the prompt might exceedtoken_limit, the plugin will generate instructions prompting the model to address each step separately.
- If
-
Paste Prompt to ChatGPT
- If the task is split into steps, simply copy/paste them one by one into ChatGPT.
-
:ChatGPTPaste- The plugin reads the YAML from your clipboard. If it requests more files, it might again suggest a step-by-step approach.
- If final changes are provided:
- Optionally preview them (
preview_changes). - Optionally partially accept them (
partial_acceptance). - The plugin then applies file creation or deletion, or applies diffs to existing files.
- Optionally preview them (
Troubleshooting & Tips
- Adjust
token_limitin.chatgpt_config.yamlas needed. - If partial acceptance is confusing, remember to remove or prepend
#to lines you don’t want before saving and closing the buffer. - If step-by-step prompting occurs, ensure you follow each prompt the model provides in the correct order.
- Check
ChatGPT_Debug_Logifimproved_debugis on, or the Neovim messages ifdebugis on, for detailed info. - You can close the selection or prompt buffers at any time with commands like
:bd,:x, or:wq. No need to rely on:q.
Debug Commands
If enable_debug_commands is true, you can include commands like these in your YAML:
commands:
- command: "list"
dir: "some/directory"
- command: "grep"
pattern: "searchString"
target: "path/to/file/or/directory"
The list command uses the system's ls command to list directory contents. The grep command searches for a given pattern in a file or all files in a directory.
Enjoy the improved, more flexible ChatGPT Neovim plugin with step-by-step and diff-based support!