Skip to content

meznaric/key-analyzer.nvim

Repository files navigation

key-analyzer.nvim

Ever wondered which mappings are free to be mapped? Now it's a easier to figure it out.

⚡️ Features

  • 🎹 Visual QWERTY keyboard layout showing your mapped and unmapped keys
  • 🔍 Analyze mappings for any prefix in any mode (normal, insert, visual, etc.)
  • 💡 Interactive hover tooltips showing the mapping details

📋 Installation

Package manager Snippet

folke/lazy.nvim

require("lazy").setup({
    { "meznaric/key-analyzer.nvim", opts = {} },
})

Usage

Command Description
:KeyAnalyzer <prefix> [mode] Shows keyboard analysis for the given prefix and mode. Mode defaults to normal ('n') if not specified.
:KeyAnalyzer <leader> Show <leader> mappings
:KeyAnalyzer <leader>b Show mappings starting with <leader>b*
:KeyAnalyzer <C- Show CTRL mappings
:KeyAnalyzer <C- v Show CTRL mappings in visual mode
:KeyAnalyzer <M- Show Alt/Meta/Option mappings
:KeyAnalyzer <M- Show Alt/Meta/Option mappings
:KeyAnalyzer <C-M>x i Show mappings starting with CTRL + M x in insert mode

:KeyAnalyzer calls this lua code: require('key-analyzer').show(prefix, mode) if you wish to map it yourself

Tip: Click or move to any key to see its mapping details

⚙ Configuration

Note: The options are also available in Neovim by calling :h key-analyzer.options

require("key-analyzer").setup({
    -- Name of the command to use for the plugin
    command_name = "KeyAnalyzer", -- or nil to disable the command
    
    -- Customize the highlight groups
    highlights = {
        bracket_used = "KeyAnalyzerBracketUsed",
        letter_used = "KeyAnalyzerLetterUsed", 
        bracket_unused = "KeyAnalyzerBracketUnused",
        letter_unused = "KeyAnalyzerLetterUnused",
        promo_highlight = "KeyAnalyzerPromo",
        
        -- Set to false if you want to define highlights manually
        define_default_highlights = true,
    },
})

Limitations

  • Not all maps will be shown. For example <C-W>, because these built in window maps are not returned by vim.api.nvim_get_keymap(mode). Another example that will not show up are also fold maps (z).
  • Currently only US-ANSII layout is supported, but feel free to open a pull request
  • There is no differentiation between upper case and lower case letters, both will show on the visualisation
  • Remember: Some keys may not actually be bindable, for example <C-[>
  • KeyAnalyzer retreives mappings with vim.api.nvim_get_keymap(mode), so local buffer mappings are not shown

⌨ Contributing

PRs and issues are always welcome. Make sure to provide as much context as possible when opening one.

Few ideas:

  • Different keyboard layouts via options
  • Add third parameter to a command buffer / global, where buffer calls nvim_buf_get_keymap
  • Bring in presets from which-key.nvim so that built-in mappings work, eg. <C-W>, z, ...

Find it interesting? X Follow

Thanks to shortcuts for the plugin boilerplate <3

About

Helping you find free keybinds in vim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published