# llvim

llvim is a neovim plugin for LLM integration with LSP support.
It provides a chat window, visual mode pasting towards the LLM, and infill for insert mode.

## Setup

You'll need curl to talk to the following (llama-server) endpoints:

- /v1/chat/completions
- /props

Include the plugin in your init.vim:

```
lua llm = require('user.llm')
```

Call the setup to configure your server and auth token:

```lua
setup("http://localhost:8080", "my_secret_token")
```

## Binding keys

You'll have to set up a few key binds to make use of the plugin.

- `infill()` completes the current function body in insert mode
- `abort()` aborts the infill process
- `visual()` opens a chat prompt and adds the visual selection as context
- `input()` opens a chat prompt

`abort` or `input` will prompt you for a query at the bottom.
After hitting enter, a new buffer will open above into which the LLM will stream its markdown answer.

This plugin doesn't try to be too smart about context.
I find that less context generally leads to more focused results.
The different functions provide different context to the LLM:

| Function | LSP Findings | Visual Selection | Entire file |
| :---     | :---         | :---             | :---        |
| `infill` | no           | no               | *yes*       |
| `visual` | *yes*        | *yes*            | no          |
| `input`  | *yes*        | no               | no          |

Your key binds may look like this:

```
inoremap <C-o> <cmd>lua llm.infill()<cr>
vnoremap <Leader>h :<C-u>lua llm.visual()<cr>
nnoremap <Leader>h :lua llm.input()<cr>
```

