https://github.com/kremovtort/caskey.nvim
Declarative keymappings configuration using cascading trees
https://github.com/kremovtort/caskey.nvim
keybindings keymap neovim neovim-plugin which-key
Last synced: 2 months ago
JSON representation
Declarative keymappings configuration using cascading trees
- Host: GitHub
- URL: https://github.com/kremovtort/caskey.nvim
- Owner: kremovtort
- License: apache-2.0
- Archived: true
- Created: 2022-12-29T12:19:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T09:32:45.000Z (over 3 years ago)
- Last Synced: 2026-02-21T04:06:11.785Z (2 months ago)
- Topics: keybindings, keymap, neovim, neovim-plugin, which-key
- Language: Lua
- Homepage:
- Size: 36.1 KB
- Stars: 67
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# caskey.nvim
Declarative **cas**cade **key** mappings configuration
## ✨ Features
- Define all your keymaps as simple lua tables
- Group keymaps the way you think about them
- Modular, declarative way to define keymaps
- Automatically registers autocommands to setup buffer local keymappings
- [Which-key](https://github.com/folke/which-key.nvim) integration out of the box
## 📦 Installation
[lazy.nvim](https://github.com/folke/lazy.nvim):
```lua
{
"Nexmean/caskey.nvim",
dependencies = {
"folke/which-key.nvim", -- optional, only if you want which-key integration
},
}
```
[packer.nvim](https://github.com/wbthomason/packer.nvim)
```lua
use {
"Nexmean/caskey.nvim",
requires = {
"folke/which-key.nvim", -- optional, only if you want which-key integration
},
}
```
## ⚙️ Configuration
Define your keymaps:
```lua
-- user/mappings.lua
local ck = require("caskey")
return {
-- options are inherits so you can define most regular at the top of keymaps config
mode = {"n", "v"},
-- Simple keymap with `caskey.cmd` helper and mode override
[""] = {act = ck.cmd "noh", desc = "no highlight", mode = "n"},
-- group keymaps to reuse options or just for config structuring
{
mode = {"i", "t", "c"},
[""] = {act = "" , desc = "Beginning of line"},
[""] = {act = "" , desc = "End of line"},
[""] = {act = "" , desc = "Move forward"},
[""] = {act = "" , desc = "Move back"},
-- override options
[""] = {act = "", desc = "Delete next character", mode = {"i", "c"}},
},
-- structure your keymaps as a tree and define which-key prefixes
["t"] = {
name = "tabs",
n = {act = ck.cmd "tabnew" , desc = "new tab"},
x = {act = ck.cmd "tabclose" , desc = "close tab"},
t = {act = ck.cmd "Telescope telescope-tabs list_tabs", desc = "list tabs"},
},
-- define buffer local keymaps
["q"] = {
act = ck.cmd "close",
desc = "close window",
when = {
ck.ft "Outline",
ck.bt {"quickfix", "help"},
-- that is equivalent to:
{
event = "FileType",
pattern = "Outline",
},
{
event = "BufWinEnter",
condition = function ()
return vim.tbl_contains({"quickfix", "help"}, vim.o.buftype)
end
}
},
},
-- use functions as config bodies
["h"] = function ()
local gs = require("gitsigns")
return {
name = "hunk",
mode = "n",
-- Sometimes there aren't events which describe that you need to setup buffer local mappings.
-- For such cases you can use custom events.
-- Caskey provides api for emitting them:
-- -- nvim/lua/user/plugins/gitsigns.lua
-- ...
-- on_attach = function (bufnr)
-- require("caskey").emit("Gitsigns", bufnr)
-- end
-- ...
--
-- And then you can use `ck.emit` to describe when to setup mappings
when = ck.emitted "Gitsigns",
s = {act = gs.stage_hunk , desc = "stage hunk"},
r = {act = gs.reset_hunk , desc = "rest hunk"},
S = {act = gs.stage_buffer , desc = "stage buffer"},
u = {act = gs.undo_stage_hunk, desc = "unstage hunk"},
d = {act = gs.preview_hunk , desc = "preview hunk"} ,
b = {act = gs.blame_line , desc = "blame line"},
}
end,
{
mode = "n",
when = "LspAttach",
["gd"] = {act = ck.cmd "Telescope lsp_definitions", desc = "lsp definition"},
[""] = {
act = ck.cmd "SymbolsOutline",
desc = "toggle outline",
-- extend mode or buffer local configuration
mode_extend = "v",
when_extend = ck.ft "Outline",
},
},
}
```
And then setup them with caskey:
```lua
require("caskey").setup(require("user.mappings"))
```
Or if you want which-key integration:
```lua
require("caskey.wk").setup(require("user.mappings"))
```
Config structure description could be found [here](https://github.com/Nexmean/caskey.nvim/wiki/Config-structure)