Git Product home page Git Product logo

ai.nvim's Introduction

ai.nvim

A Neovim plugin powered by Google Gemini.

2.mp4

Installation

First get an API key from Gemini. It's free!

Using lazy.nvim:

{
  'gera2ld/ai.nvim',
  dependencies = 'nvim-lua/plenary.nvim',
  opts = {
    api_key = 'YOUR_GEMINI_API_KEY', -- or read from env: `os.getenv('GEMINI_API_KEY')`
    -- The locale for the content to be defined/translated into
    locale = 'en',
    -- The locale for the content in the locale above to be translated into
    alternate_locale = 'zh',
    -- Gemini's answer is displayed in a popup buffer
    -- Default behaviour is not to give it the focus because it is seen as a kind of tooltip
    -- But if you prefer it to get the focus, set to true.
    result_popup_gets_focus = false,
    -- Define custom prompts here, see below for more details
    prompts = {},
  },
  event = 'VeryLazy',
},

Usage

Built-in Commands

" Define the word under cursor
:GeminiDefineCword

" Define the word or phrase selected or passed to the command
:'<,'>GeminiDefine
:GeminiDefine happy

" Translate content selected or passed to the commmand
:'<,'>GeminiTranslate
:GeminiTranslate I am happy.

" Improve content selected or passed to the command
" Useful to correct grammar mistakes and make the expressions more native.
:'<,'>GeminiImprove
:GeminiTranslate Me is happy.

" Ask anything
:GeminiAsk Tell a joke.

Custom Prompts

opts = {
  prompts = {
    rock = {
      -- Create a user command for this prompt
      command = 'GeminiRock',
      loading_tpl = 'Loading...',
      prompt_tpl = 'Tell a joke',
      result_tpl = 'Here is your joke:\n\n$output',
      require_input = false,
    },
  },
}

The prompts will be merged into built-in prompts. Here are the available fields for each prompt:

Fields Required Description
command No If defined, a user command will be created for this prompt.
loading_tpl No Template for content shown when communicating with Gemini. See below for available placeholders.
prompt_tpl Yes Template for the prompt string passed to Gemini. See below for available placeholders.
result_tpl No Template for the result shown in the popup. See below for available placeholders.
require_input No If set to true, the prompt will only be sent if text is selected or passed to the command.

Placeholders can be used in templates. If not available, it will be left as is.

Placeholders Description Availability
${locale} opts.locale Always
${alternate_locale} opts.alternate_locale Always
${input} The text selected or passed to the command. Always
${input_encoded} The text encoded with JSON so that Gemini will take it as literal instead of a new prompt. Always
${output} The result returned by Gemini. After the request

We can either call a prompt with the associated command:

:GeminiRock

or with its name:

:lua require('ai').handle('rock')

Related Projects

  • coc-ai - A coc.nvim plugin powered by Gemini

ai.nvim's People

Contributors

gera2ld avatar rakotomandimby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.