-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented gptme.vim plugin (#241)
- Loading branch information
Showing
4 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# gptme Vim Plugin | ||
|
||
A Vim plugin for [gptme](https://gptme.org) integration, allowing you to interact with gptme directly from your editor. | ||
|
||
## Features | ||
|
||
- Run gptme queries with context from your current buffer | ||
- Automatically includes surrounding lines as context | ||
- Results shown in a new buffer | ||
- Configurable context size and key mappings | ||
|
||
## Installation | ||
|
||
### Using a Plugin Manager | ||
|
||
#### [vim-plug](https://github.com/junegunn/vim-plug) | ||
|
||
Add this to your `.vimrc`: | ||
|
||
Plug 'ErikBjare/gptme', { 'rtp': 'scripts/vim' } | ||
|
||
Then run: | ||
|
||
:PlugInstall | ||
|
||
### Manual Installation | ||
|
||
Copy the contents of this directory to your ~/.vim directory: | ||
|
||
cp -r plugin doc ~/.vim/ | ||
|
||
## Usage | ||
|
||
The plugin provides both a command and a default mapping: | ||
|
||
- `:gptme` - Prompts for input and runs gptme with context | ||
- `<Leader>g` - Same as :gptme (usually `\g`) | ||
|
||
When invoked, it will: | ||
1. Prompt for your input | ||
2. Get context from around your cursor | ||
3. Run gptme with both inputs | ||
4. Show the result in a new buffer | ||
|
||
## Configuration | ||
|
||
You can configure the following settings in your `.vimrc`: | ||
### Context Lines | ||
|
||
Set the number of context lines to include before and after cursor (default: 3): | ||
|
||
let g:gptme_context_lines = 5 | ||
|
||
### Key Mappings | ||
|
||
Disable default key mappings: | ||
|
||
let g:gptme_no_mappings = 1 | ||
|
||
If you disable the default mappings, you can set your own: | ||
|
||
nnoremap <Leader>G :gptme<CR> | ||
|
||
## License | ||
|
||
Same as Vim itself - see `:help license` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
*gptme.txt* gptme integration for Vim | ||
|
||
Author: Erik Bjäreholt | ||
License: Same terms as Vim itself (see |license|) | ||
|
||
INTRODUCTION *gptme* | ||
|
||
This plugin provides integration with gptme (https://gptme.org), allowing you to | ||
interact with gptme directly from Vim. | ||
|
||
USAGE *gptme-usage* | ||
|
||
The plugin provides both a command and a default mapping: | ||
|
||
:Gptme Prompts for input and runs gptme with context | ||
<Leader>g Same as :Gptme | ||
|
||
When invoked, it will: | ||
1. Prompt for your input | ||
2. Get context from around your cursor | ||
3. Run gptme with both inputs | ||
4. Show the result in a new buffer | ||
|
||
CONFIGURATION *gptme-config* | ||
|
||
*g:gptme_context_lines* | ||
Number of context lines to include before and after cursor (default: 3) | ||
> | ||
let g:gptme_context_lines = 5 | ||
< | ||
|
||
*g:gptme_no_mappings* | ||
Disable default key mappings (default: 0) | ||
> | ||
let g:gptme_no_mappings = 1 | ||
< | ||
|
||
ABOUT *gptme-about* | ||
gptme.vim plugin version 0.1 | ||
Latest version at: https://github.com/ErikBjare/gptme | ||
|
||
vim:tw=78:ts=8:ft=help:norl: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
" gptme.vim - gptme integration for Vim | ||
" Maintainer: Erik Bjäreholt | ||
" Version: 0.1 | ||
|
||
if exists('g:loaded_gptme') | ||
finish | ||
endif | ||
let g:loaded_gptme = 1 | ||
|
||
" Default settings | ||
if !exists('g:gptme_context_lines') | ||
let g:gptme_context_lines = 3 | ||
endif | ||
|
||
function! s:gptme() range | ||
" Check if range was given (visual selection) | ||
let l:has_range = a:firstline != a:lastline | ||
|
||
if l:has_range | ||
" Get visually selected lines | ||
let l:context = getline(a:firstline, a:lastline) | ||
else | ||
" Get context around cursor | ||
let l:current_line = line('.') | ||
let l:start_line = max([1, l:current_line - g:gptme_context_lines]) | ||
let l:end_line = min([line('$'), l:current_line + g:gptme_context_lines]) | ||
let l:context = getline(l:start_line, l:end_line) | ||
endif | ||
|
||
let l:context_text = join(l:context, "\n") | ||
let l:ft = empty(&filetype) ? '' : &filetype | ||
let l:filename = expand('%:p') | ||
|
||
" Now get input from user | ||
let l:input = input('gptme prompt: ') | ||
if empty(l:input) | ||
return | ||
endif | ||
|
||
" Build the prompt with proper escaping | ||
let l:prompt = l:input . " at:\n```" . l:ft . "\n" . l:context_text . "\n```" | ||
|
||
" Build the command with proper shell escaping | ||
let l:cmd = 'gptme ' . shellescape(l:prompt) . ' ' . shellescape(l:filename) | ||
|
||
" Debug: Show command (optional) | ||
echom "Command: " . l:cmd | ||
|
||
" Open terminal in a new window | ||
vertical new | ||
file gptme | ||
|
||
" Use appropriate terminal function based on Vim/Neovim | ||
if has('nvim') | ||
call termopen(l:cmd) | ||
" Auto-enter insert mode in terminal (Neovim) | ||
startinsert | ||
else | ||
call term_start(l:cmd, {'curwin': 1}) | ||
endif | ||
endfunction | ||
|
||
" Map it to <Leader>g (usually \g) unless user disabled default mappings | ||
if !exists('g:gptme_no_mappings') | ||
nnoremap <Leader>g :call <SID>gptme()<CR> | ||
" Add visual mode mapping | ||
vnoremap <Leader>g :call <SID>gptme()<CR> | ||
endif | ||
|
||
" Command interface (note the capital G) | ||
command! -range Gptme <line1>,<line2>call <SID>gptme() |