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
- Host: GitHub
- URL: https://github.com/std-enigma/mapper.nvim
- Owner: Std-Enigma
- License: gpl-3.0
- Created: 2024-06-22T00:39:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-29T10:21:47.000Z (almost 2 years ago)
- Last Synced: 2024-06-29T17:59:32.945Z (almost 2 years ago)
- Topics: keybindings, keymap, keymapping, neovim, neovim-configuration, neovim-lua, neovim-lua-plugin, neovim-plugin, which-key
- Language: Lua
- Homepage:
- Size: 32.2 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
[](https://lua.org)