sponsor Vim development Vim logo Vim Book Ad

gpt-vim : brings chat gpt to Vim and NVim

 script karma  Rating 7/4, Downloaded by 534  Comments, bugs, improvements  Vim wiki

created by
ayman khamouma
 
script type
utility
 
description
# vim-gpt

This plugin brings chat gpt to Vim and NVim
The purpose of this pugin is to assist you for your various development tasks.

Demo time: https://github.com/kamou/gpt-vim/blob/master/uml2rust.gif
## Current Features

- Chat with GPT (currently gpt3.5-turbo) in a separate buffer. The output is in markdown.
- GPT can recall previous messages from the current session.
- Selected text/code is appended to the prompt.
- GPT is aware of the language of your current buffer.
- Multiple sessions. You can save a session and continue the conversation later if needed.

## Requirements

Requirement can be installed using the following command:
```
pip3 install -r requirements.txt
```

## Installation
```vim
Plug 'kamou/gpt-vim'
```

## Available commands
```
:call gpt#Assist(0)      # Launch the prompt
:'<,'>call gpt#Assist(1) # Launch the prompt and append the current selection
```

## Default keymapping configuration
```
nmap <silent> gpa <Plug>(gpt-vim-assist)
xmap <silent> gpa <Plug>(gpt-vim-assist-vis)
vmap <silent> gpa <Plug>(gpt-vim-assist-vis)
```
You may update it in you .vimrc file.

## GPT buffer keys
  - `r` reset current session memory, GPT will forget everything, the buffer will be cleared
  - `q` close gpt buffer. Memory is kept untouched, gpt will recall previous (most recent) messages.
  - `s` save the current session history
  - `L` list previously saved sessions (press enter to load selected session)
  - `c` Cancel the current stream. (The answer will be lost, and not saved in the database)
  - `Y` Enter Yank Mode. [Experimental, mapping willl change soon]

## Yank Mode
  - `j` Cycle down to next fenced code block.
  - `k` Cycle up to next fenced code block.
  - `<cr>` Copy current block and leave Yank Mode.

## Session list keys
  - `q` close the list
  - `d` delete the session under the cursor
  - `<cr>` select the session under the cursor
  - `s`: Open the conversation under the cursor in a horizontal split.
  - `v`: Open the conversation under the cursor in a vertical split.

 
install details
## Requirements

- an openai [api key](https://platform.openai.com/account/api-keys) (add `g:gpt_api_key` to your config)
- sqlite3, openai and tiktoken python package
```sh
pip install sqlite3
pip install openai
pip install tiktoken
```

## Installation
```vim
Plug 'kamou/gpt-vim'
```

## Available commands
```
:call gpt#assist([sessionname])             # Launch the prompt
:'<,'>call gpt#visual_assist([sessionname]) # Launch the prompt and append the current selection
```


## Sample keymapping configuration
```
map <silent> <leader><space> :<C-U>call gpt#assist()<cr>
xnoremap <silent> <leader><space> :'<,'>call gpt#visual_assist()<cr>
vnoremap <silent> <leader><space> :'<,'>call gpt#visual_assist()<cr>
```
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
gpt-vim.tgz 0.10 2024-01-01 8.1 ayman khamouma Bump openai python package version
gpt-vim.tgz 0.9 2023-09-04 9.0 ayman khamouma The assistant can now execute generated python and lua code just like int chat-gpt interpreter mode
The assistant can also search the web (google, ddg and wikipedia) and read web pages content.
gpt-vim.tgz 0.8 2023-04-27 8.0 ayman khamouma more refactoring. multiple chat buffers support. fenced code block Yank Mode support
gpt-vim.tgz 0.7 2023-04-24 8.0 ayman khamouma Fix crash on missing database
gpt-vim.tgz 0.6 2023-04-24 8.0 ayman khamouma Refactoring, Bugfixes, and a doc generated by the plugin ¯\_(ツ)_/¯
gpt-vim.tgz 0.5 2023-04-22 8.0 ayman khamouma Bugfix (empty list after buffer quit)
gpt-vim.tgz 0.4 2023-04-22 8.0 ayman khamouma Bugfixes + ability to delete a session.
gpt-vim.tgz 0.2 2023-04-20 7.0 ayman khamouma Improved sessions
gpt-vim.tgz 0.1 2023-04-20 8.0 ayman khamouma Initial upload
ip used for rating: 3.226.72.194

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github