An open API service indexing awesome lists of open source software.

https://github.com/std-enigma/mapper.nvim

A different approach to set NeoVim key mappings
https://github.com/std-enigma/mapper.nvim

keybindings keymap keymapping neovim neovim-configuration neovim-lua neovim-lua-plugin neovim-plugin which-key

Last synced: 6 months ago
JSON representation

A different approach to set NeoVim key mappings

Awesome Lists containing this project

README

          

# ⌨️ Mapper

An alternative solution to setup your neovim key mappings.

## ⚡️ Requirements

- Neovim >= 0.5.0

## ⚠️ Caution

which-key.nvim registration isn't possible if you are using any package manager rather than [lazy.nvim](https://github.com/folke/lazy.nvim)

## 📦 Installation

Install the plugin with your preferred package manager:

### [lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
{
"Std-Enigma/mapper.nvim",
opts = {}, -- for setting up your mappings, refer to the usage section.
}
```

## 💡 API

**Mapper** provides a Lua API with key mapping functionality. This can be viewed with `:h mapper` or in the repository at [doc/api.md](doc/api.md)

## 🚀 Usage

### Lazy Plugin

Lazy

```lua
{
"Std-Enigma/mapper.nvim",
opts = {
mappings = {
-- map mode (:h map-modes)
n = {
[""] = { ":w!", desc = "Save File" }, -- use vimscript strings for mappings
L = {
function() vim.cmd.bnext() end, -- use lua functions for mappings
desc = "Next buffer",
},
H = {
function() vim.cmd.bprevious() end, -- use lua functions for mappings
desc = "Previous buffer",
},
-- tables with just a `desc` key will be registered with which-key if it's installed
-- this is useful for naming menus
["b"] = { desc = "Buffers" },
},
},
},
}
```

Usage with other plugins

```lua
{
"mrjones2014/smart-splits.nvim",
dependencies = {
{
"Std-Enigma/mapper.nvim",
opts = function(_, _)
local maps = require("mapper").empty_map_table()
maps.n[""] = { function() require("smart-splits").move_cursor_left() end, desc = "Move to left split" }
maps.n[""] = { function() require("smart-splits").move_cursor_down() end, desc = "Move to below split" }
maps.n[""] = { function() require("smart-splits").move_cursor_up() end, desc = "Move to above split" }
maps.n[""] = { function() require("smart-splits").move_cursor_right() end, desc = "Move to right split" }
maps.n[""] = { function() require("smart-splits").resize_up() end, desc = "Resize split up" }
maps.n[""] = { function() require("smart-splits").resize_down() end, desc = "Resize split down" }
maps.n[""] = { function() require("smart-splits").resize_left() end, desc = "Resize split left" }
maps.n[""] = { function() require("smart-splits").resize_right() end, desc = "Resize split right" }
return { mappings = maps } -- we do this so lazy.nvim can merge your mappings table
end,
},
},
opts = {},
}
```

### Lua API

API

You can setup your mappings like so with the api:

```lua
local mapper = require("mapper")
local mappings = mapper.empty_map_table()

-- tables with just a `desc` key will be registered with which-key if it's installed
-- this is useful for naming menus
mappings.n["b"] = { desc = "Buffers" }
mappings.n["L"] = { function() vim.cmd.bnext() end, desc = "Next buffer" } -- use lua functions for mappings
mappings.n["H"] = { function() vim.cmd.bprevious() end, desc = "Previous buffer" } -- use lua functions for mappings
mappings.n[""] = { "silent! update! | redraw", desc = "Force write" } -- use vimscript strings for mappings
maps.i[""] = { "" .. maps.n[""][1], desc = maps.n[""].desc } -- you can use already defined mappings properties since this is just a lua table

mapper.set_mappings(mappings)
```

## ⭐ Credits

This plugin is a direct implementation of [AstroNvim](https://github.com/AstroNvim/AstroNvim) core utilities for setting up key mappings.

[![Lua](https://img.shields.io/badge/Made%20with%20Lua-blue.svg?style=for-the-badge&logo=lua)](https://lua.org)