114 lines
5.1 KiB
Markdown
114 lines
5.1 KiB
Markdown
<!-- README.md -->
|
||
# ChatGPT NeoVim Plugin (Extensively Updated with Step-by-Step Prompting)
|
||
|
||
This plugin integrates a ChatGPT O1 model workflow into Neovim. It allows you to:
|
||
|
||
1. Generate prompts containing:
|
||
- An **initial prompt** (loaded from `.chatgpt_config.yaml` or `chatgpt_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_contents` flag is enabled
|
||
|
||
2. Copy these prompts to your clipboard to paste into ChatGPT O1.
|
||
3. Receive YAML changes from ChatGPT and run `:ChatGPTPaste` to 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 configured `prompt_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**:
|
||
If `partial_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**:
|
||
If `preview_changes: true`, a buffer will show the proposed changes before they are applied.
|
||
|
||
- **Interactive File Selection**:
|
||
When `interactive_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 flag `include_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 the `prompt_char_limit`, it notifies you to disable this feature to avoid exceeding the model’s capacity.
|
||
|
||
- **Improved Debug**:
|
||
If `improved_debug: true`, detailed debug logs are sent to a dedicated `ChatGPT_Debug_Log` buffer for easier review.
|
||
|
||
## Example `.chatgpt_config.yaml` or `chatgpt_config.yaml`
|
||
|
||
```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
|
||
|
||
1. **`:ChatGPT`**
|
||
- If `interactive_file_selection` is enabled, you will select directories via a buffer (named `ChatGPT_File_Selection`).
|
||
- Save and close the buffer with `:wq`, `:x`, or `:bd` (no need to use `:q`).
|
||
- If `enable_step_by_step` is active and the prompt might exceed `prompt_char_limit`, the plugin will generate a step-by-step instruction prompt.
|
||
|
||
2. **Paste Prompt to ChatGPT**
|
||
- If the task is split into steps, copy and paste them one by one into ChatGPT.
|
||
|
||
3. **`: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.
|
||
|
||
## Troubleshooting & Tips
|
||
|
||
- Adjust `prompt_char_limit` in 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_Log` buffer (if `improved_debug` is enabled) or the standard Neovim messages (if `debug` is 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:
|
||
```yaml
|
||
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:**
|
||
```vim
|
||
:set rtp^=~/temp_plugins/chatgpt.vim
|
||
```
|
||
|
||
- **Clear Lua module cache:**
|
||
```vim
|
||
:lua for k in pairs(package.loaded) do if k:match("^chatgpt_nvim") then package.loaded[k]=nil end end
|
||
```
|
||
|
||
- **Load new plugin code:**
|
||
```vim
|
||
:runtime plugin/chatgpt.vim
|
||
```
|