readmes/mini-keymap.md
See more details in Features and Documentation.
[!NOTE] This was previously hosted at a personal
echasnovskiGitHub account. It was transferred to a dedicated organization to improve long term project stability. See more details here.
⦿ This is a part of mini.nvim library. Please use this link if you want to mention this module.
⦿ All contributions (issues, pull requests, discussions, etc.) are done inside of 'mini.nvim'.
⦿ See whole library documentation to learn about general design principles, disable/configuration recipes, and more.
⦿ See MiniMax for a full config example that uses this module.
If you want to help this project grow but don't know where to start, check out contributing guides of 'mini.nvim' or leave a Github star for 'mini.nvim' project and/or any its standalone Git repositories.
https://github.com/user-attachments/assets/a3e34e9f-6901-4e57-a5bd-9508b2c6d065
Map keys to perform configurable multi-step actions: if condition for step one is true - execute step one action, else check step two, and so on until falling back to executing original keys. This is usually referred to as "smart" keys (like "smart tab"). See :h MiniKeymap.map_multistep().
There are many built-in steps targeted for Insert mode mappings of special keys like <Tab>, <S-Tab>, <CR>, and <BS>:
<CR> and <BS> respecting mini.pairs.:h vim.snippet).<CR> and <BS> respecting windwp/nvim-autopairs.Map keys as "combo": each key acts immediately plus execute extra action if all are typed within configurable delay between each other. See :h MiniKeymap.map_combo().
Some of the common use cases include:
Sources with more details:
:h MiniKeymap-examplesSetup that works well with 'mini.completion' and 'mini.pairs':
local map_multistep = require('mini.keymap').map_multistep
map_multistep('i', '<Tab>', { 'pmenu_next' })
map_multistep('i', '<S-Tab>', { 'pmenu_prev' })
map_multistep('i', '<CR>', { 'pmenu_accept', 'minipairs_cr' })
map_multistep('i', '<BS>', { 'minipairs_bs' })
"Better escape" to Normal mode without having to reach for <Esc> key:
local map_combo = require('mini.keymap').map_combo
-- Support most common modes. This can also contain 't', but would
-- only mean to press `<Esc>` inside terminal.
local mode = { 'i', 'c', 'x', 's' }
map_combo(mode, 'jk', '<BS><BS><Esc>')
-- To not have to worry about the order of keys, also map "kj"
map_combo(mode, 'kj', '<BS><BS><Esc>')
-- Escape into Normal mode from Terminal mode
map_combo('t', 'jk', '<BS><BS><C-\\><C-n>')
map_combo('t', 'kj', '<BS><BS><C-\\><C-n>')
Show notification if there is too much movement by repeating same key:
local notify_many_keys = function(key)
local lhs = string.rep(key, 5)
local action = function() vim.notify('Too many ' .. key) end
require('mini.keymap').map_combo({ 'n', 'x' }, lhs, action)
end
notify_many_keys('h')
notify_many_keys('j')
notify_many_keys('k')
notify_many_keys('l')
This plugin can be installed as part of 'mini.nvim' library (recommended) or as a standalone Git repository.
There are two branches to install from:
main (default, recommended) will have latest development version of plugin. All changes since last stable release should be perceived as being in beta testing phase (meaning they already passed alpha-testing and are moderately settled).stable will be updated only upon releases with code tested during public beta-testing phase in main branch.Here are code snippets for some common installation methods (use only one):
<details> <summary>With <a href="https://nvim-mini.org/mini.nvim/readmes/mini-deps">mini.deps</a></summary>'mini.nvim' library:
| Branch | Code snippet |
|---|---|
| Main | Follow recommended 'mini.deps' installation |
| Stable | Follow recommended 'mini.deps' installation |
Standalone plugin:
| Branch | Code snippet |
|---|---|
| Main | add('nvim-mini/mini.keymap') |
| Stable | add({ source = 'nvim-mini/mini.keymap', checkout = 'stable' }) |
'mini.nvim' library:
| Branch | Code snippet |
|---|---|
| Main | { 'nvim-mini/mini.nvim', version = false }, |
| Stable | { 'nvim-mini/mini.nvim', version = '*' }, |
Standalone plugin:
| Branch | Code snippet |
|---|---|
| Main | { 'nvim-mini/mini.keymap', version = false }, |
| Stable | { 'nvim-mini/mini.keymap', version = '*' }, |
'mini.nvim' library:
| Branch | Code snippet |
|---|---|
| Main | Plug 'nvim-mini/mini.nvim' |
| Stable | Plug 'nvim-mini/mini.nvim', { 'branch': 'stable' } |
Standalone plugin:
| Branch | Code snippet |
|---|---|
| Main | Plug 'nvim-mini/mini.keymap' |
| Stable | Plug 'nvim-mini/mini.keymap', { 'branch': 'stable' } |
Important: no need to call require('mini.keymap').setup(), but it can be done to improve usability.
Note: if you are on Windows, there might be problems with too long file paths (like error: unable to create file <some file name>: Filename too long). Try doing one of the following:
git config --system core.longpaths true. Then try to reinstall.-- No need to copy this inside `setup()`. Will be used automatically.
{}