Skip to content

Commit

Permalink
chore(build): auto-generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 23, 2024
1 parent 8c8902a commit b94a7d5
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/mappings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Mappings
description: How mappings work in care.nvim
sidebar_position: 2
---

# Mappings

## Usage

For basic mappings the user should use the provided `<Plug>` mappings.

- `<Plug>(CareConfirm)`: Confirm the currently selected entry
- `<Plug>(CareSelectNext)`: Select the next entry in the menu
- `<Plug>(CareSelectPrev)`: Select the previous entry in the menu
- `<Plug>(CareClose)`: Close the completion menu

These mappings will automatically fallback to the default actions of the keys
mapped if the menu isn't open. That means that if `<CR>` is mapped to confirm
like this

```lua
vim.keymap.set("i", "<cr>", "<Plug>(CareConfirm)")
```

pressing `<CR>` will still go to a new line when the completion menu isn't open.

<!--TODO: link to api docs-->

To create more advanced mappings the api should be used. For fallback to the
unmapped action of a key `nvim_feedkeys` can be used. An example for this would
be the following:

```lua
vim.keymap.set("i", "<c-f>", function()
if require("care").api.doc_is_open() then
require("care").api.scroll_docs(4)
else
vim.api.nvim_feedkeys(vim.keycode("<c-f>"), "n", false)
end
end)
```

## Design

When designing the mapping system it was important that as much native
functionality as possible is used. Therefore it was really important that the
mappings could be set by the user with `vim.keymap.set` without any additional
abstractions.

To have the best possible user experience `<Plug>` mappings are used for some
simple mappings while still allowing to create more complex mappings which do
multiple things with one key.

0 comments on commit b94a7d5

Please sign in to comment.