• Stars
    star
    293
  • Rank 140,994 (Top 3 %)
  • Language
    Lua
  • License
    ISC License
  • Created almost 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate and edit text in Neovim using OpenAI and GPT.

πŸ€– ai.vim

A minimalist Neovim plugin for generating and editing text using OpenAI and GPT.

Features

  • Complete text in insert mode.
  • Generate new text using a prompt.
  • Select and edit existing text in-place.
  • Streaming support for completions.
  • Easy to use interface. Just hit <Ctrl-A> or run :AI <prompt>.
  • Works with both source code and regular text.

Installing

For vim-plug, add this to your init.vim:

Plug 'aduros/ai.vim'

Make sure you have an environment variable called $OPENAI_API_KEY which you can generate here. You'll also need curl installed.

To see the full help and customization options, run :help ai.vim.

Tutorial

The most basic use-case is completion, by pressing <Ctrl-A> in insert mode.

For example:

function capitalize (str: string): string {
    (Press <Ctrl-A> here)
}

Will result in:

function capitalize (str: string): string {
    return str.charAt(0).toUpperCase() + str.slice(1);
}

ai.vim isn't just for programming! You can also complete regular human text:

Hey Joe, here are some ideas for slogans for the new petshop. Which do you like best?
1. <Ctrl-A>

Results in:

Hey Joe, here are some ideas for slogans for the new petshop. Which do you like best?
1. "Where Pets Come First!"
2. "Your Pet's Home Away From Home!"
3. "The Best Place for Your Pet!"
4. "The Pet Store That Cares!"
5. "The Pet Store That Loves Your Pet!"

You can also generate some text by pressing <Ctrl-A> in normal mode and providing a prompt. For example:

:AI write a thank you email to Bigco engineering interviewer

Results in something like:

Dear [Name],

I wanted to take a moment to thank you for taking the time to interview me for the engineering
position at Bigco. I was very impressed with the company and the team, and I am excited about the
possibility of joining the team.

I appreciate the time you took to explain the role and the company's mission. I am confident that I
have the skills and experience to be a valuable asset to the team.

Once again, thank you for your time and consideration. I look forward to hearing from you soon.

Sincerely,
[Your Name]

Besides generating new text, you can also edit existing text using a given instruction.

body {
    color: orange;
    background: green;
}

Visually selecting the above CSS and running :AI convert colors to hex results in:

body {
    color: #ffa500;
    background: #008000;
}

Another example of text editing:

List of capitals:
1. Toronto
2. London
3. Honolulu
4. Miami
5. Boston

Visually selecting this text and running :AI sort by population results in:

List of capitals:
1. London
2. Toronto
3. Boston
4. Miami
5. Honolulu

You can build your own shortcuts for long and complex prompts. For example:

vnoremap <silent> <leader>f :AI fix grammar and spelling and replace slang and contractions with a formal academic writing style<CR>

With this custom mapping you can select text that looks like this:

Me fail English? That's unpossible!

And by pressing <leader>f transform it into this:

I failed English? That is impossible!

If you come up with any exciting ways to use ai.vim, please share what you find!

Important Disclaimers

Accuracy: GPT is good at producing text and code that looks correct at first glance, but may be completely wrong. Make sure you carefully proof read and test everything output by this plugin!

Privacy: This plugin sends text to OpenAI when generating completions and edits. Don't use it in files containing sensitive information.

More Repositories

1

wasm4

Build retro games using WebAssembly for a fantasy console.
TypeScript
1,129
star
2

flambe

Rapidly cook up games for HTML5, Flash, Android, and iOS.
Haxe
742
star
3

webuxn

Web runtime for the uxn virtual machine.
C
76
star
4

hydra

An HTML5 game engine for the many faces of mobile WebKit.
JavaScript
64
star
5

flambe-demos

Demos and example code for Flambe.
Haxe
50
star
6

dotfiles

My configuration and theme.
Shell
35
star
7

pjs

An awk-like command-line tool for processing text, CSV, JSON, HTML, and XML.
JavaScript
24
star
8

easel

A 2D scene graph and game engine for HTML5 (canvas) in haXe. Easel is intended to feel natural to Flash developers.
Haxe
16
star
9

dts2haxe

Typescript .d.ts to Haxe extern generator.
Python
15
star
10

Browser.hx

JS externs for Haxe.
Haxe
14
star
11

lintgpt

LintGPT scans your code for bugs using AI.
TypeScript
14
star
12

space-date

A short visual novel
Haxe
7
star
13

popcord

Watch videos together with friends, remotely.
JavaScript
6
star
14

SDL_image

Unofficial git mirror of SDL_image
C
4
star
15

clipboy

Clipboy is a cross-platform, minimal clipboard manager.
Go
4
star
16

hanoi

A Flash/HTML5 game built in a weekend
Haxe
4
star
17

SDL_mixer

Unofficial git mirror of SDL_mixer
C
4
star
18

vigrep

Grep for image files using GPT-4o Vision.
TypeScript
4
star
19

thimble

Anti-fingerprinting browser extension.
TypeScript
4
star
20

trollcat

A Trollscript interpreter written in LOLCODE
3
star
21

SDL

Unofficial git mirror of SDL
C
3
star
22

amity

Getting along with Android and iPhone game development
C
3
star
23

flambe-server

Flambe extensions for multiplayer games
Haxe
2
star
24

lime-volleyball

A WASM-4 game jam entry
C
2
star
25

carebot

A friendly Twitter bot that corrects mentions of "could care less".
Python
1
star
26

webidl-externs

WebIDL
1
star
27

check-tmpmail

JavaScript
1
star
28

camocat

Anti-SEO text transformer.
Go
1
star