GithubHelp home page GithubHelp logo

folke / which-key.nvim Goto Github PK

View Code? Open in Web Editor NEW
4.5K 12.0 147.0 371 KB

πŸ’₯ Create key bindings that stick. WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible keybindings of the command you started typing.

License: Apache License 2.0

Lua 99.88% Vim Script 0.12%
neovim neovim-plugin neovim-lua lua

which-key.nvim's Introduction

πŸ’₯ Which Key

WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible key bindings of the command you started typing. Heavily inspired by the original emacs-which-key and vim-which-key.

image

✨ Features

  • for Neovim 0.7 and higher, it uses the desc attributes of your mappings as the default label
  • for Neovim 0.7 and higher, new mappings will be created with a desc attribute
  • opens a popup with suggestions to complete a key binding
  • works with any setting for timeoutlen, including instantly (timeoutlen=0)
  • works correctly with built-in key bindings
  • works correctly with buffer-local mappings
  • extensible plugin architecture
  • built-in plugins:
    • marks: shows your marks when you hit one of the jump keys.
    • registers: shows the contents of your registers
    • presets: built-in key binding help for motions, text-objects, operators, windows, nav, z and g
    • spelling: spelling suggestions inside the which-key popup

⚑️ Requirements

  • Neovim >= 0.5.0

πŸ“¦ Installation

Install the plugin with your preferred package manager:

{
  "folke/which-key.nvim",
  event = "VeryLazy",
  init = function()
    vim.o.timeout = true
    vim.o.timeoutlen = 300
  end,
  opts = {
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
  }
}
-- Lua
use {
  "folke/which-key.nvim",
  config = function()
    vim.o.timeout = true
    vim.o.timeoutlen = 300
    require("which-key").setup {
      -- your configuration comes here
      -- or leave it empty to use the default settings
      -- refer to the configuration section below
    }
  end
}

βš™οΈ Configuration

❗️ IMPORTANT: the timeout when WhichKey opens is controlled by the vim setting timeoutlen. Please refer to the documentation to properly set it up. Setting it to 0, will effectively always show WhichKey immediately, but a setting of 500 (500ms) is probably more appropriate.

❗️ don't create any keymappings yourself to trigger WhichKey. Unlike with vim-which-key, we do this fully automatically. Please remove any left-over triggers you might have from using vim-which-key.

πŸš‘ You can run :checkhealth which-key to see if there's any conflicting keymaps that will prevent triggering WhichKey

WhichKey comes with the following defaults:

{
  plugins = {
    marks = true, -- shows a list of your marks on ' and `
    registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
    -- the presets plugin, adds help for a bunch of default keybindings in Neovim
    -- No actual key bindings are created
    spelling = {
      enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
      suggestions = 20, -- how many suggestions should be shown in the list?
    },
    presets = {
      operators = true, -- adds help for operators like d, y, ...
      motions = true, -- adds help for motions
      text_objects = true, -- help for text objects triggered after entering an operator
      windows = true, -- default bindings on <c-w>
      nav = true, -- misc bindings to work with windows
      z = true, -- bindings for folds, spelling and others prefixed with z
      g = true, -- bindings for prefixed with g
    },
  },
  -- add operators that will trigger motion and text object completion
  -- to enable all native operators, set the preset / operators plugin above
  operators = { gc = "Comments" },
  key_labels = {
    -- override the label used to display some keys. It doesn't effect WK in any other way.
    -- For example:
    -- ["<space>"] = "SPC",
    -- ["<cr>"] = "RET",
    -- ["<tab>"] = "TAB",
  },
  motions = {
    count = true,
  },
  icons = {
    breadcrumb = "Β»", -- symbol used in the command line area that shows your active key combo
    separator = "➜", -- symbol used between a key and it's label
    group = "+", -- symbol prepended to a group
  },
  popup_mappings = {
    scroll_down = "<c-d>", -- binding to scroll down inside the popup
    scroll_up = "<c-u>", -- binding to scroll up inside the popup
  },
  window = {
    border = "none", -- none, single, double, shadow
    position = "bottom", -- bottom, top
    margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]. When between 0 and 1, will be treated as a percentage of the screen size.
    padding = { 1, 2, 1, 2 }, -- extra window padding [top, right, bottom, left]
    winblend = 0, -- value between 0-100 0 for fully opaque and 100 for fully transparent
    zindex = 1000, -- positive value to position WhichKey above other floating windows.
  },
  layout = {
    height = { min = 4, max = 25 }, -- min and max height of the columns
    width = { min = 20, max = 50 }, -- min and max width of the columns
    spacing = 3, -- spacing between columns
    align = "left", -- align columns left, center or right
  },
  ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
  hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "^:", "^ ", "^call ", "^lua " }, -- hide mapping boilerplate
  show_help = true, -- show a help message in the command line for using WhichKey
  show_keys = true, -- show the currently pressed key and its label as a message in the command line
  triggers = "auto", -- automatically setup triggers
  -- triggers = {"<leader>"} -- or specifiy a list manually
  -- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
  triggers_nowait = {
    -- marks
    "`",
    "'",
    "g`",
    "g'",
    -- registers
    '"',
    "<c-r>",
    -- spelling
    "z=",
  },
  triggers_blacklist = {
    -- list of mode / prefixes that should never be hooked by WhichKey
    -- this is mostly relevant for keymaps that start with a native binding
    i = { "j", "k" },
    v = { "j", "k" },
  },
  -- disable the WhichKey popup for certain buf types and file types.
  -- Disabled by default for Telescope
  disable = {
    buftypes = {},
    filetypes = {},
  },
}

πŸͺ„ Setup

With the default settings, WhichKey will work out of the box for most builtin keybindings, but the real power comes from documenting and organizing your own keybindings.

To document and/or setup your own mappings, you need to call the register method

local wk = require("which-key")
wk.register(mappings, opts)

Default options for opts

{
  mode = "n", -- NORMAL mode
  -- prefix: use "<leader>f" for example for mapping everything related to finding files
  -- the prefix is prepended to every mapping part of `mappings`
  prefix = "",
  buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  silent = true, -- use `silent` when creating keymaps
  noremap = true, -- use `noremap` when creating keymaps
  nowait = false, -- use `nowait` when creating keymaps
  expr = false, -- use `expr` when creating keymaps
}

❕ When you specify a command in your mapping that starts with <Plug>, then we automatically set noremap=false, since you always want recursive keybindings in this case

⌨️ Mappings

⌨ for Neovim 0.7 and higher, which key will use the desc attribute of existing mappings as the default label

Group names use the special name key in the tables. There's multiple ways to define the mappings. wk.register can be called multiple times from anywhere in your config files.

local wk = require("which-key")
-- As an example, we will create the following mappings:
--  * <leader>ff find files
--  * <leader>fr show recent files
--  * <leader>fb Foobar
-- we'll document:
--  * <leader>fn new file
--  * <leader>fe edit file
-- and hide <leader>1

wk.register({
  f = {
    name = "file", -- optional group name
    f = { "<cmd>Telescope find_files<cr>", "Find File" }, -- create a binding with label
    r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File", noremap=false, buffer = 123 }, -- additional options for creating the keymap
    n = { "New File" }, -- just a label. don't create any mapping
    e = "Edit File", -- same as above
    ["1"] = "which_key_ignore",  -- special label to hide it in the popup
    b = { function() print("bar") end, "Foobar" } -- you can also pass functions!
  },
}, { prefix = "<leader>" })
Click to see more examples
-- all of the mappings below are equivalent

-- method 2
wk.register({
  ["<leader>"] = {
    f = {
      name = "+file",
      f = { "<cmd>Telescope find_files<cr>", "Find File" },
      r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
      n = { "<cmd>enew<cr>", "New File" },
    },
  },
})

-- method 3
wk.register({
  ["<leader>f"] = {
    name = "+file",
    f = { "<cmd>Telescope find_files<cr>", "Find File" },
    r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
    n = { "<cmd>enew<cr>", "New File" },
  },
})

-- method 4
wk.register({
  ["<leader>f"] = { name = "+file" },
  ["<leader>ff"] = { "<cmd>Telescope find_files<cr>", "Find File" },
  ["<leader>fr"] = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  ["<leader>fn"] = { "<cmd>enew<cr>", "New File" },
})

Tips: The default label is keymap.desc or keymap.rhs or "", :h nvim_set_keymap() to get more details about desc and rhs.

πŸš™ Operators, Motions and Text Objects

WhichKey provides help to work with operators, motions and text objects.

[count]operator[count][text-object]

  • operators can be configured with the operators option
    • set plugins.presets.operators to true to automatically configure vim built-in operators
    • set this to false, to only include the list you configured in the operators option.
    • see here for the full list part of the preset
  • text objects are automatically retrieved from operator pending key maps (omap)
    • set plugins.presets.text_objects to true to configure built-in text objects
    • see here
  • motions are part of the preset plugins.presets.motions setting
How to disable some operators? (like v)
-- make sure to run this code before calling setup()
-- refer to the full lists at https://github.com/folke/which-key.nvim/blob/main/lua/which-key/plugins/presets/init.lua
local presets = require("which-key.plugins.presets")
presets.operators["v"] = nil

πŸš€ Usage

When the WhichKey popup is open, you can use the following key bindings (they are also displayed at the bottom of the screen):

  • hit one of the keys to open a group or execute a key binding
  • <esc> to cancel and close the popup
  • <bs> go up one level
  • <c-d> scroll down
  • <c-u> scroll up

Apart from the automatic opening, you can also manually open WhichKey for a certain prefix:

❗️ don't create any keymappings yourself to trigger WhichKey. Unlike with vim-which-key, we do this fully automatically. Please remove any left-over triggers you might have from using vim-which-key.

:WhichKey " show all mappings
:WhichKey <leader> " show all <leader> mappings
:WhichKey <leader> v " show all <leader> mappings for VISUAL mode
:WhichKey '' v " show ALL mappings for VISUAL mode

πŸ”₯ Plugins

Four built-in plugins are included with WhichKey.

Marks

Shows a list of your buffer local and global marks when you hit ` or '

image

Registers

Shows a list of your buffer local and global registers when you hit " in NORMAL mode, or <c-r> in INSERT mode.

image

Presets

Built-in key binding help for motions, text-objects, operators, windows, nav, z and g

image

Spelling

When enabled, this plugin hooks into z= and replaces the full-screen spelling suggestions window by a list of suggestions within WhichKey.

image

🎨 Colors

The table below shows all the highlight groups defined for WhichKey with their default link.

Highlight Group Defaults to Description
WhichKey Function the key
WhichKeyGroup Keyword a group
WhichKeySeparator DiffAdd the separator between the key and its label
WhichKeyDesc Identifier the label of the key
WhichKeyFloat NormalFloat Normal in the popup window
WhichKeyBorder FloatBorder Normal in the popup window
WhichKeyValue Comment used by plugins that provide values

which-key.nvim's People

Contributors

alaviss avatar apppppppple avatar ccaseiro avatar cmcaine avatar folke avatar frantisekstanko avatar github-actions[bot] avatar gustavobat avatar herringtondarkholme avatar joseconseco avatar joshnavi avatar levouh avatar loneexile avatar mariasolos avatar mdoury avatar michaelb avatar mitinarseny avatar mivort avatar mly32 avatar muniftanjim avatar nimaipatel avatar owittek avatar pflakus avatar ranjithshegde avatar samantha-uk avatar tapayne88 avatar tmillr avatar unrealapex avatar xiyaowong avatar zeertzjq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

which-key.nvim's Issues

<Plug> commands not working?

Hi! I love this plugin!

I just can't seem to get my commands to work... For example:

f = {'<Plug>(esearch)', 'Search in project'}

Am I putting them in wrong?

Feature request: hide group if it doesn't contain any mappings

Hi, first of all, thanks for this awesome plugin, it rocks!

It would be awesome if groups that have no mapping associated to it in the current buffer didn't show up. My use case is mappings for LSP functions, which are only set when an LSP server is attached, so the +lsp group would only show up in buffers that have attached an LSP server, and not in others.

key sorting

image

Would you be opposed to grouping all non-alphabetical then Aa-Zz (as opposed to A-Z, then a-z)?

`<<` always triggers which-key popup menu

I've currently only encountered this problem with <<, leading me to believe it's a bug.
Whenever I try to change the indentation level by using the above keybind the popup window shows up, meaning I have to press < a third time to actually proceed with the indent.
>> works as expected and does not give any issues :)

The current workaround for this is selecting the line (Shift + v) and then using < to indent, but that's rather tedious.

Best way to avoid remapped key warning

Hello,

which-key looks excellent and will be super helpful in mastering more obscure shortcuts!

I'm currently using https://github.com/cohama/lexima.vim which adds some additional keymapping for , and I also using:

vim.g.mapleader = " "

What would be the best way to avoid triggering warning from

Util.warn(string.format(
"Your <leader> key for %q mode in buf %d is currently mapped to %q. WhichKey automatically creates triggers, so please remove the mapping",
mode, buf or 0, keymap.rhs))
? Is this something on which-key side or maybe lexima?

Cheers

Pressing < in normal mode

Hi! I'm having an issue when pressing '<' in normal mode, the which-key prompt is brought up at the lowest level, what would normally be << to indent to the left is now <<<. :WhichKey '<' brings up what I would expect however.

I'm assuming that this is not the desired behaviour.

`<' - mapping seems to be breaking wk

Hello @folke which key in lua is great. I just wonder what could happen today that config below wont work today and it worked yesterday...

wk.register({
	['<leader>S'] = { ':Startify<CR>',                'Startify' },
	['<leader>/'] = { ':Ag<CR>',                      'Search Project' },            --<plug>fzf,
	['<leader>.'] = { ':Telescope find_files<CR>',    'Find File' },
	['<leader>:'] = { ':Telescope commands<CR>',      'Commands' },
	['<leader><'] = { ':Telescope buffers<CR>',       'Switch Buffer' },
	["<leader>%"] = { ':<C-o><CR>',                   'Switch to last buffer<CR>' }, --<plug>bufftabs,
	['<leader>r'] = { ':luafile $MYVIMRC<CR>',        'Reload VIMRC' },
	['<leader> '] = { ':HopChar2<CR>',                'HOP 2Char' },
	['<leader>e'] = { ':Fern . -reveal=%<CR>',        'File Browser' },
	['<leader>p'] = { 'viwP<CR>',                     'Paste over word' },
	['<leader>1'] = { '=echo ""<CR>',             'Buffer' },
})  

The problematic entry seems to be:
['<leader><'] = { ':Telescope buffers<CR>', 'Switch Buffer' },
When I remove it the which-key works ok. The < character seems to be breaking wk, when I use different character then it works ok again ... or am I doing something wrong?

highlight groups

whichkeyfloat seems to change whichkeyseperator, but not the other way around.

Disable key

Everybody was waiting for which-key in lua so thanks!

I want to disable the which-key pop-up for all keybindings starting with d,y,c etc. So I put everything to false:

presets = {
	operators = false, -- adds help for operators like d, y, ...
	motions = false, -- adds help for motions
	text_objects = false, -- help for text objects triggered after entering an operator
	windows = false, -- default bindings on <c-w>
	nav = false, -- misc bindings to work with windows
	z = true, -- bindings for folds, spelling and others prefixed with z
	g = true, -- bindings for prefixed with g
}

But I still see a pop up for 'ds' , 'ys' from the vim-surround plugin. Or 'ca' - for code actions from Lsp Saga etc.

Is there a way to disable everything for a specific key?

Thank you in advance!

E5107: Error loading lua [string ":lua"]:1: ')' expected near 'n'

Hi , Having a blast using your plugin btw .

I am using default configurations. I only have this in my plugins file.

  -- which key
  use {
    "folke/which-key.nvim",
    config = function()
      require("which-key").setup {
        -- your configuration comes here
        -- or leave it empty to use the default settings
        -- refer to the configuration section below
      }
    end
  }

If it's relevant somehow:

I am using \ as my key leader vim.g.mapleader = '\\'
and timeoutlen=0

How to Reproduce

Happens after I press my leader key twice.
which closes the which-key window.
And produces the error E5107: Error loading lua [string ":lua"]:1: ')' expected near 'n'

Aftermath: the which-key window wouldn't trigger if I press my leader key and produces the E5107 error.
But it still works with registers, visual mode and while changing words/lines

Assigning lua reserved keys

Is there a way to create mappings using the methods in 1-3 in the readme using special keys? It may just be my linter but I'm getting a lot of errors when writing my config.

My use case is buffer navigation grouped on Alt with bprev and bnext on alt + . and alt + , respectively

Many thanks for all your great plugins

Appear below status line

First of all, i just want to thank you guys for the awesome plugin! Secondly, i would like to know if it's possible to make which-key appear below the status line just like vim-which-key? I feel like whenever I open which-key everything is so big and using unnecessary space. It would also be nice for it to display in one single line if the mappings count is less than a certain number.
Here is a screenshot below of vim-which-key vs which-key

Which-key
Screenshot from 2021-05-01 15-22-45

invalid mode shortname

image

Is this on me?

To give this plugin a quick test run, I tried setting it up for descriptions only. So

  1. in packer: use {'folke/which-key.nvim', config = [[require('wk')]]}
  2. wk.lua just has the copy pasta default opts inside the wk.setup function, and then require('maps')
  3. maps.lua is a longer version of:
local wk = require('which-key') 
local opts = {mode = 'n', prefix = '<leader>', buffer = nil, silent = true}
local maps = {
  [','] = 'comment',
  ['.'] = 'vimrc',
  [';'] = 'substitute',
  ['\\'] = 'nv tree',
  ['<Left>'] = 'mv buffer next',
  ['<Right>'] = 'mv buffer previous',
  ['='] = 'balance windows',
  ['h'] = 'split below',
  ['H'] = 'treesitter highlight',
  ['j'] = 'any jump',
  ['k'] = 'pick buffer',
}
wk.register(maps, opts)

Question: How to modify group names ?

There's no way I can get the group names to show up. I've already used some examples configs from the README but none of them seen to work for me.

2021-May- 3

As you can see all of the groups that have more keybindings inside only show +prefix. I've basically tried all the methods from the README. This is what I currently have:

local opts = {
    mode = "n", -- NORMAL mode
    prefix = "<leader>",
    buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
    silent = true, -- use `silent` when creating keymaps
    noremap = true, -- use `noremap` when creating keymaps
    nowait = false -- use `nowait` when creating keymaps
}

local mappings = {
    f = {
        name = "file", -- optional group name
        f = {"<cmd>Telescope find_files<cr>", "Find File"} -- create a binding with label
    }
}

local wk = require("which-key")
wk.register(mappings, opts)

Right now I'm testing with <leader>f and I haven't mange to make it show +find as a group name instead of +prefix. Can anyone point me in the right direction ? or tell what am I doing wrong.

Highlighting WhichKeyFloat doesn't have effect

hi WhichKeyFloat ctermbg=NONE ctermfg=NONE
I have this line in my vimrc, but it doesn't seem to have any effect. Note, however, that after I have started vim and I manually type out : hi WhichKeyFloat ctermbg=NONE ctermfg=NONE the desired effect is achieved and background color of which key becomes transparent. For some reason it doesn't work in vimrc, though.

How to open command line but not execute

I couldn't find anything about this in the documentation nor in the issues.

I used to have nnoremap <leader>gg :GrepperRg<space> but I don't know how to convert this to a which key mapping.

i = {":GrepperGit", "Search for something in Git files"} variations of this always require me to press a key so that the command line shows :GrepperGit . I tried appending <space> and various other things but none worked.

Typing leader key three times will show error when the leader key is `\`

Typing leader key three times will show error when the leader key is \

But if the leader key is ,, there are no issues.

The error message is Error loading lua [string ":lua"]:1: ')' expected near 'n'.

nvim version: v0.5.0-dev+1282-gfbe18d9ca

which-key.nvim: 2844e1c

vimrc:

"let mapleader=","
filetype off                  " required before plugins

silent! call plug#begin('~/.config/nvim/plugged')
if has('nvim-0.5')
  Plug 'https://github.com/folke/which-key.nvim'
endif

call plug#end()

silent! call denite#custom#map('insert', '<C-j>', '<denite:move_to_next_line>', 'noremap')
silent! call denite#custom#map('insert', '<C-k>', '<denite:move_to_previous_line>', 'noremap')

syntax enable
filetype plugin indent on     " required!

nnoremap <silent> <leader>lb :C brow<cr>

Thank you for your help.

High startup time

Hi πŸ‘‹πŸΎ thanks for creating this plugin, it solves quite a lot of issues I had with the vimscript version of whichkey.

After installing it and setting up some mappings I noticed an increase in my startup time. I did some profiling using packer's profiling feature and noticed that it's quite expensive to load.

image

It also appears to have increased the load time for configuring other plugins where I added wk.register calls. I'm not sure if wk.register has to be used sparingly or not but adding these call seems to really add up.

I'm not sure if it uses any of the deep_extend methods under the hood but I've noted in the past that these are quite expensive.

To verify this yourself (if you use packer) you can set

config = {
 profile = {
   enabled = true
 }
}

Run PackerCompile then reload neovim and run PackerProfile to see the output

Breaks targets.vim plugin

Pretty sure I've minimally reproduced with only which-key and targets enabled in my vimrc. Which-key seems to break targets.
Given the following snippet

 \begin{A} ────────────┬────┐
           ───────┐    β”‚    β”‚
   a       ──┐    β”‚    β”‚    β”‚
   a        2Ile 2ile 2ale 2Ale
   a       β”€β”€β”˜    β”‚    β”‚    β”‚
           β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚    β”‚
 \end{A}   β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
           β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

with targets.vim pressing 2ile should visually select the text, but with which-key enabled there's a conflict that breaks targets.vim

Support (visual only) mapmode 'x'

Following:

wk.register({ i = { h = {':<C-U>lua require"gitsigns".select_hunk()<CR>', 'Git hunk'}}}, {mode = "x"})

results in:

WhichKey: Invalid mode "x" for buf 0

while the same with "v" as mode works as (almost) expected.

Conflicting with Insert mode mappings

I have the classic mappings for

inoremap jk <Esc>
inoremap kj <Esc>

So when I press j or k in insert mode, which key get activated and can't write those letters, so when I don't want to esc, I just want to write j or k, I can't.
γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2021-05-01 19 46 49

Breaks g mappings in help text for me

Here's my configuration

wk = require("which-key")

wk.setup {
    plugins = {
        marks = true,
        registers = true,
        presets = {
            operators = false,
            motions = false,
            text_objects = false,
            windows = false,
            nav = false,
            z = false,
            g = false,
        },
    },
}

If I open a new tab and then open help newtab | h lua I can no longer use gt to switch tabs. The cursor jumps to the first position in the command line at the bottom and nothing happens until I hit ctrl-c which then gives me E5108: Error executing lua Keyboard interrupt which is probably expected.

Running :map gt in the help buffer and an empty buffer in the same tab gives me:

For the help buffer where gt is broken

n  g           *@<Cmd>lua require("which-key").show("g", {mode = "n", auto = true})<CR>
n  g           * <Cmd>lua require("which-key").show("g", {mode = "n", auto = true})<CR>
v  g           * <Cmd>lua require("which-key").show("g", {mode = "v", auto = true})<CR>

For the other buffer where it works

n  g           * <Cmd>lua require("which-key").show("g", {mode = "n", auto = true})<CR>
v  g           * <Cmd>lua require("which-key").show("g", {mode = "v", auto = true})<CR>

Disable visual mappings

Is there a way to stop triggering WhichKey at v key mappings? I'm trying to enter visual mode without triggering it but it isn't possible

Already tried with

wk.register({['v'] = 'which_key_ignore'})

but the key bindings keep coming out when pressing v πŸ˜•

Keybindings triggering operator pending commands

Right now, WhichKey doesn't play nice with commands that trigger operator pending mode, like kommentary and others.

The flow to decide whether the typed keys need to be send back with or without remap is as follows:

  • if this is a leaf of the mapping tree, check if it has a cmd attached
    • if a cmd, then with remap
    • else, without remap to trigger builtin keybindings
  • if a key was entered that doesnt exist in the tree, we feed back without remap, since no keymapping was found

The above doesn't work with for example gciw

The gc part is a command, but the full prefix fails at gci, so we expect it to be a native mapping.

The fix is to only send back keys with remap, if the cmd and non of its ancestors have a cmd. (excluding whichkey cmds)

I'll work on it for tomorrow :)

See also #2

Feature Request: `:checkhealth` check for duplicate mappings

I have my mappings separated into different files by plugin and right now if I overwrite one mapping with a different one it can be hard to tell that I did. I'd like to have a config option to enable checks for overriding mappings. If this is a feature you're okay with I'd be willing to do a pr for it.

issue with plugin (commentary)

What a wonderful plugin!
Planning to try out with all my plugin with default whichkey config first.

So far I have the following problems.

  1. Does not load prefix related to tpope's commentary plugin. only shows the first level after pressing 'g' (c->plug commentary)
  2. If timeout length is set to small, because of no prefix popup, gcc does not work
  3. for yank, delete, change, treesitter-textobjects dont work regardless of timeout length (exaple: ac -around conditional, al-around loop, af-around function....)

Will report more as they come in.

Overrides <C-W> terminal normal mode binding by default

Pretty sure this is what's be causing me issues with <C-W>N to trigger terminal normal mode.
Output from :verbose nnoremap:

n  <C-W>Þ      * <Nop>
	Last set from ~/.vim/plugged/which-key.nvim/plugin/which-key.vim line 2
n  <C-W>       * <Cmd>lua require("which-key").show("\23", {mode = "n", auto = true})<CR>
	Last set from ~/.vim/plugged/which-key.nvim/plugin/which-key.vim line 2

visual & select mode issues

cannot replace text in select mode if the proposed replacement text starts with 'i', or 'a' as it will trigger which-key prefixes (inside, around)

##Issue:
When pressing i or a in select mode it puts in visual mode with prefix for other keymap completions.

##steps to reproduce:

  1. select a text/range-text in visual mode and press C-g (or any other way of entering select mode)
  2. Press i to replace the text selected a word starting with i (Ex: while using For loop snippets in C, "int i = 0")

Error after last commit

After the last commit I get this error
image

I found out that the problem is that i set a custom leader key (space), and that if i keep the default leader key I no longer get the error. I tried to set the leader key after the WhichKey setup, but it didn't work that way either. Is there a way I can set a custom leader key?

Edit: forgot to mention, the leader key is set through vim.g.mapleader = ' '

How to map with Plug?

Hi Folke,
Using which-key plugin that has being converted to lua was insane improvement to quick and slickness.

There is something I haven't gotten to work with this plugin.

let g:which_key_map['z'] = [ '<Plug>(zoom-toggle)' , 'zoom' ]

This worked with the old plugin

When I tried to convert into lua , I haven't figured out why it doesnt seem to work at all.

vim.api.nvim_set_keymap("n", "<leader>z", "<Plug>(zoom-toggle)", {noremap = true, silent = true})

Any clue what I might be missing with this syntax?

Possibility to map ctrl

How i can map Ctrl in this way??

which_key.register({
  ["<Ctrl>"] = {
      name = "+Windows",
      ["<left>"] =  "Switch left window",
  },
})

Hydra mode

In emacs there is awesome plugin Hydra that allows you to stick in mapping submode eg lest way we have debug mappings:

<leader>dd   -start debug
<leader>dn   -next
<leader>db   -breakpoint add
<leader>de   -end debug

With hydra we can go into <leader>``d - mode and stay there - no we can press n - multiple times to continue debugging (rather than using full mapping - <leader>dn, <leader>dn ,<leader>dn each time
I'm not sure it this would be possible with which-key?
<ret> could 'pin' current which-key state, q (or esc) could quit the pin mode.

Create mappings to lua functions directly

One thing that i'm really missing is a way to map stuff to lua functions directly, rather than going through luaeval.
Specifically, as i'm using fennel (transpile to lua), this is a big missing feature.

From what I've seen, the best way to implement this would be to store the functions that are provided in some table by ID, and then generate mappings that call that table ID.
This would be a big improvement to config and usability here ^^

`yank to register` doesn't work

yank to register doesn't work.

For example, when I type "ayy, it doesn't store anything in register a

NVIM v0.5.0-dev+1282-gfbe18d9ca

which-key.nimv version: 410523a

vimrc

set nocompatible              " be improved
filetype off                  " required before plugins

silent! call plug#begin('~/.config/nvim/plugged')
if has('nvim-0.5')
  Plug 'https://github.com/folke/which-key.nvim'
endif

call plug#end()

syntax enable
filetype plugin indent on     " required!

Thank you for your help.

Test report

Ok I've tried it and have found some issues . So letting you know .

  1. lazy load maps from packer are a mess. I've some prefix maps that is used to lazy load specific plugins . like t for telescope then telscope config maps it's kemaps with t as prefix as tf when telescope is loaded . Packer creats the mapt when it's invoked it loades the plugin runs the config (creating the keymaps) they puts the editor is state that prefix was pressed . Now the issue which-key can't see the keymaps that are later lazy loaded . Actually real issue is packer and which-key keeps going back and forth which key invokes packer and packer invokes which key (kind of like a recursion I assume until next key is pressed) causing curspr to jump arround .
  2. For some reason I'm not getting g keys though g = true is set
  3. The float height and width doesn't account for border causing border in right and below are off the screen.

It's a great plugin . You can let me know where I'm wrong in these .

Feature request: Support for local leader

Hi! I just wanted to say thank you for this plugin. I've been using the old which key for a while. But when I recently ported over my config to lua, I found that there was a lot of functionality I would like that wasn't quite there. And this plugin has a lot of that, so thank you!

Anyway, everything is working great, but I'd like to request that <LocalLeader> be supported the same way that <Leader> currently is.

Thanks, again!

Display which-key on leader key only

Thank for your plugin

Hi i just want to display which-key on leader key. Currently it mapping all key g,d,y,... and I don't want that.
I only want to display on leader.

My setup function

        wk.setup {
            plugins = {
                marks = false, -- shows a list of your marks on ' and `
                registers = false, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
                -- the presets plugin, adds help for a bunch of default keybindings in Neovim
                -- No actual key bindings are created
                presets = false
            },
        }

it only hide the description but it still display which-key on my mapping.

Strange behaviour

Everything was working fine, I did a :PackerUpdate and then I have the following behaviour:

  • When I press <space> (my leader key) no pop-up menu is shown the same if I call :WhichKey <leader>
  • If I press <space>a which is a group that I have created the pop-up menu appears.
  • If I press " for registers the pop-up menu appears again.
  • All the keybindings mapped through which-key work.

I don't know why the leader key alone doesn't show the pop-up menu. Literally, one hour ago everything was ok and I didn't change anything. I even reverted back to a previous commit of which-key.nvim but nothing happened. I don't know if an update of a different plugin somehow messed up which-key.

Feature : Add page no in the bottom

Currently the popup always says to scroll up and to scroll down . But there's no indicator how far can be scrolled or if there are maps out of page at all . A count at the bottom will help understand how many pages are left that can be scrolled .

Triggering if I finish the key combination

I'm sure this is just something I messed up, but I can't understand where is the problem. If I finish a key combination fast enough not to trigger Which Key, it still opens.
image
This is an example of what I get if I open the file browser, and if I press esc everything works fine. I also tried to to a key combination slow enough to pop the menu immediately, and again everything works fine (same thing with timeoutlen = 0)

Invalid mode "'" for buf 0

On the current HEAD I'm getting the following the first time WhichKey is supposed to be displayed.

WhichKey: Invalid mode "'" for buf 0 (please report this issue if it persists)
WhichKey: Invalid mode passed to :WhichKey (Dont create any keymappings to trigger WhichKey. WhichKey does this automaytically) (please report this issue if it persists)
Press ENTER or type command to continue

What's odd is that it seems to solve itself after a while, I'm not entirely sure what I am doing that triggers it. After (re)starting nvim I get the above error consistently though.

Catch keyboard interrupt and handle it as Escape

First off, great plugin!

Sometimes out of habit, I hit <c-c> to cancel. When I do it with which-key, I get the following error:
image

It then takes me back to my previous window but leaves the which-key panel open. I can't switch back to the which-key panel to close it, the only way is to trigger it again and then exit it properly with escape.

It would be nice if which key handled <c-c> in the same way as escape

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.