Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benknoble/popsikey
Turn vim mappings into popups
https://github.com/benknoble/popsikey
vim vim-plugin
Last synced: 3 months ago
JSON representation
Turn vim mappings into popups
- Host: GitHub
- URL: https://github.com/benknoble/popsikey
- Owner: benknoble
- License: mit
- Created: 2020-06-28T21:33:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-28T18:02:00.000Z (about 2 years ago)
- Last Synced: 2024-07-14T00:16:39.381Z (7 months ago)
- Topics: vim, vim-plugin
- Language: Vim Script
- Homepage:
- Size: 14.6 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# popsikey
[![This project is considered experimental](https://img.shields.io/badge/status-experimental-critical.svg)](https://benknoble.github.io/status/experimental/)
Vim plugin that turns prefixed mappings into pop-up menus.
## What is it?
If you have lots of vim mappings that relate to the same subject, you may have
"namespaced" them by using a prefix.As an example, suppose all of your git mappings start with `g`:
- `gg` is `:Gstatus`
- `gc` is `:Gcommit`popsikey provides an interface to automatically turn those mappings into a popup
menu when it's supported. With our example mappings, you would create this by
doingcall popsikey#register('g', [
\ #{key: 'g', info: 'status', action: ":Gstatus\", flags: 'n'},
\ #{key: 'c', info: 'commit', action: ":Gcommit\", flags: 'n'},
\ ],
\ {})So, `g` pops up the menu of git mappings, which is a list of map keys
and descriptions. You navigate with the usual keys (`j`, `k`, ``,
``). But your mappings work--so pressing `g` inside the popup will
trigger `:Gstatus` as a shortcut to navigating the menu.And, if your vim doesn't support popups yet, you'll get regular old mappings:
nnoremap gg :Gstatus
nnoremap gc :GcommitThat means the experience is seamless everywhere.
**Note** only global normal-mode mappings, without modifiers, are currently
supported.## How do I use it?
Install it, and then call `popsikey#register` (note that I used `const` and `->`
methods liberally in the code, so your vim will need to support those).The `popsikey#register` function takes the following arguments:
- `prefix`: the mapping prefix, like `g`
- `maps`: a list of mapping dictionaries. Each must contain the following keys
(strings):
- `key`: the key on which to trigger the mapping (without the prefix)
- `info`: a short description of the action for this mapping
- `action`: the action to take (this will be fed to `feedkeys`, so you may
need double-quotes and backslash-escapes on special characters like ``)
- `flags`: a string of `feedkeys` flags. If `flags` would cause keys not be
mapped by `feedkeys` and popups are unavailable, the created mappings are
non-recursive. Otherwise, the mappings are recursive.
- `opts`: a dictionary of options to pass to `popup_create` (see `:help
popup_create-arguments`). Merged with a default of
```vim
#{
\ filter: 'popsikey#filter',
\ callback: 'popsikey#callback',
\ title: prefix,
\ padding: [1,2,1,2],
\ pos: 'topleft',
\ line: 'cursor+1',
\ col: 'cursor',
\ }
```Do not override `filter` or `callback`, or you will break the menu's
key-handlers.This should be enough to get started with most setups. If you need more
customization, check out `:help popsikey`.## What if I don't have prefixed mappings?
Then this probably isn't going to be a plugin or a solution you need--after the
first stroke of non-prefixed mapping, there's nothing left to "popup."Most default keybindings are mnemonically named. I found that when creating my
own keybindings, however, I often namespaced related operations together by
using a second prefix under leader and left general operations as single keys
under my leader.