5.1 KiB
ChatGPT NeoVim Plugin (Extensively Updated with Step-by-Step Prompting)
This plugin integrates a ChatGPT O1 model workflow into Neovim. It allows you to:
-
Generate prompts containing:
- An initial prompt (loaded from
.chatgpt_config.yamlorchatgpt_config.yaml) - A list of directories (as specified in your configuration) from which it gathers the project structure
- Interactive file selection (if enabled) so you can choose which directories to include
- Any initial files you define (e.g.
README.md, etc.) - Optionally, file contents can be appended to the prompt when the new
include_file_contentsflag is enabled
- An initial prompt (loaded from
-
Copy these prompts to your clipboard to paste into ChatGPT O1.
-
Receive YAML changes from ChatGPT and run
:ChatGPTPasteto apply them or to supply additional files.
New Key Features
-
Step-by-Step Prompting (
enable_step_by_step: true):
If the generated prompt grows too large (exceeding the configuredprompt_char_limit), the plugin automatically produces a special prompt asking the model to split the task into smaller steps. This ensures you remain within the model’s maximum token capacity without manually breaking your task apart. -
Partial Acceptance:
Ifpartial_acceptance: true, you can open a buffer displaying the proposed changes. Remove or comment out lines you do not wish to apply, and only the remaining changes will be executed. -
Preview Changes:
Ifpreview_changes: true, a buffer will show the proposed changes before they are applied. -
Interactive File Selection:
Wheninteractive_file_selection: true, you can choose which directories (from your config file) to include in the prompt, thus managing token usage more effectively. -
Include File Contents:
A new configuration flaginclude_file_contents(default:false) lets you include the entire contents of the project files in the prompt. When enabled, the plugin gathers and appends the file contents from the selected directories. It counts the total characters and, if the combined file contents exceed theprompt_char_limit, it notifies you to disable this feature to avoid exceeding the model’s capacity. -
Improved Debug:
Ifimproved_debug: true, detailed debug logs are sent to a dedicatedChatGPT_Debug_Logbuffer for easier review.
Example .chatgpt_config.yaml or chatgpt_config.yaml
project_name: "chatgpt_nvim"
default_prompt_blocks:
- "basic-prompt"
- "workflow-prompt"
directories:
- "."
initial_files:
- "README.md"
debug: false
include_file_contents: false # Set to true to include file contents in the prompt
enable_step_by_step: true
preview_changes: true
interactive_file_selection: true
partial_acceptance: true
improved_debug: true
prompt_char_limit: 300000 # Maximum characters allowed in the prompt
Usage
-
:ChatGPT- If
interactive_file_selectionis enabled, you will select directories via a buffer (namedChatGPT_File_Selection). - Save and close the buffer with
:wq,:x, or:bd(no need to use:q). - If
enable_step_by_stepis active and the prompt might exceedprompt_char_limit, the plugin will generate a step-by-step instruction prompt.
- If
-
Paste Prompt to ChatGPT
- If the task is split into steps, copy and paste them one by one into ChatGPT.
-
:ChatGPTPaste- The plugin reads the YAML response from your clipboard. If additional files are requested, a step-by-step approach might be suggested.
- When final changes are provided:
- You can optionally preview them (
preview_changes). - You can optionally partially accept them (
partial_acceptance). - Finally, the plugin applies file writes or deletions as specified in the YAML.
- You can optionally preview them (
Troubleshooting & Tips
- Adjust
prompt_char_limitin your configuration file as needed. - If partial acceptance is confusing, simply remove or comment out lines you do not want before finalizing the buffer.
- When step-by-step prompting occurs, ensure you follow each instruction in the correct order.
- For detailed debug information, check the
ChatGPT_Debug_Logbuffer (ifimproved_debugis enabled) or the standard Neovim messages (ifdebugis enabled). - You can close the selection or prompt buffers at any time using commands like
:bd,:x, or:wq.
Debug Commands
If enable_debug_commands is true, you can include commands such as:
commands:
- command: "list"
dir: "some/directory"
- command: "grep"
pattern: "searchString"
target: "path/to/file/or/directory"
The list command uses the Linux ls command to list directory contents, while the grep command searches for a given pattern within files or directories.
Enjoy your improved, flexible ChatGPT NeoVim plugin with step-by-step support and enhanced file inclusion capabilities!
Test when Developing
-
Add plugin to runtimepath:
:set rtp^=~/temp_plugins/chatgpt.vim -
Clear Lua module cache:
:lua for k in pairs(package.loaded) do if k:match("^chatgpt_nvim") then package.loaded[k]=nil end end -
Load new plugin code:
:runtime plugin/chatgpt.vim