Skip to content

farhanmustar/cg.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

CG.vim

  • Vim plugin to query to OpenAI API.
  • While there are already a few ChatGPT plugins available, this plugin aims to replicate the behavior of CS.vim and vim-fugitive. Specifically, the aim is to recreate the commit message buffer behavior in vim-fugitive.
  • This plugin make use of curl application to query information directly from vim. Makesure curl is executable by vim.
  • Execute this command in vim to check:
:echo executable('curl')

Installation

Plugin 'farhanmustar/cg.vim'
Plug 'farhanmustar/cg.vim'

OpenAI API Key

  • Users need to supply api key to g:cg_api_key variable.
  • To supply it directly in .vimrc
let g:cg_api_key = 'YOUR_SECRET_API_KEY_WAITING_TO_BE_EXPOSED_OR_PUSH_TO_REPO'
  • To supply it through environment variable where you set the api key to it.
let g:cg_api_key = getenv('YOUR_ENV_VARIABLE_NAME_THAT_SHOULD_NOT_EXIST')
  • To supply it through file that contain the api key (assuming it is on the first line).
let g:cg_api_key = readfile(glob('~/.PATH_TO_FILE_THAT_SHOULD_NEVER_BE_THERE'))[0]
let g:cg_api_key = trim(g:cg_api_key)

Functionality

  • Add 3 new command:
:CG your query     " single completion query.
:CGC your query    " Chat query, usage will be shown below.
:CGCode your query " Similar to `:CGC` but added initial user message to ensure only code reply.

" Chat Buffer Key Maps (for CGC and CGCode command only).
cc " Open commit buffer to send next message (empty message will treat as cancel new msg)
<  " Navigate to previous conversation.
>  " Navigate to next conversation

Demo 1

  • Demonstrate :CG command to query for python method to hash multiple files.
  • Then manually set the opened CG buffer to python filetype for syntax highlighting.

CG Demo

Demo 2

  • Demonstrate :CGC command to query for python method to hash multiple files.
  • Then cc keymap is pressed to open commit buffer to reply for better answer with the following query:
    But i want to read all files content then hash temp all into single hash value
  • Then manually set the opened CG buffer to python filetype for syntax highlighting.

CGC Demo

Demo 3

  • Demonstrate :CGCode command to query for python method to hash multiple files.
  • Then cc keymap is pressed to open commit buffer to reply for better answer with the following query:
    But i want to hash all files into single hash value
  • Reply again with following message to cleanup the suggested answer:
    Can we do it without reading it by chunk
  • Finally navigate to previous and next conversation using < and > keymap.

CGCode Demo

DISCLAIMER

This software is provided "AS IS" and WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. The author is not liable for any damages or losses arising from the use of the software. The software is not intended to provide professional advice. The author shall not be held accountable for any misuse of the software. By using this software, you agree to be bound by these terms and conditions.

ᓚᘏᗢ . . . miau

About

ChatGPT plugin for vim.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published