All Projects ā†’ liuchengxu ā†’ Vim Which Key

liuchengxu / Vim Which Key

šŸŒ· Vim plugin that shows keybindings in popup

Projects that are alternatives of or similar to Vim Which Key

Context.vim
Vim plugin that shows the context of the currently visible buffer contents
Stars: āœ­ 688 (-47.48%)
Mutual labels:  neovim, vim-plugin
Vimrc
šŸ“ Vim Configuration for nerds with vim-plug
Stars: āœ­ 33 (-97.48%)
Mutual labels:  neovim, vim-plugin
Crease.vim
Easy foldtext customization for [neo]vim.
Stars: āœ­ 19 (-98.55%)
Mutual labels:  neovim, vim-plugin
Tmux Complete.vim
Vim plugin for insert mode completion of words in adjacent tmux panes
Stars: āœ­ 447 (-65.88%)
Mutual labels:  neovim, vim-plugin
Vim Grepper
šŸ‘¾ Helps you win at grep.
Stars: āœ­ 1,030 (-21.37%)
Mutual labels:  neovim, vim-plugin
Vim Markdown Composer
An asynchronous markdown preview plugin for Vim and Neovim.
Stars: āœ­ 501 (-61.76%)
Mutual labels:  neovim, vim-plugin
Hot Reload.vim
A (Neo)vim plugin for Flutter to automatically hot reload the project every time a file is saved
Stars: āœ­ 33 (-97.48%)
Mutual labels:  neovim, vim-plugin
Barbar.nvim
A neovim tabline plugin.
Stars: āœ­ 359 (-72.6%)
Mutual labels:  neovim, vim-plugin
Todoist.nvim
A todoist extension for neovim
Stars: āœ­ 84 (-93.59%)
Mutual labels:  neovim, vim-plugin
Vim Outdated Plugins
šŸ”„ Async Vim/Neovim plugin for showing the number of your outdated plugins
Stars: āœ­ 44 (-96.64%)
Mutual labels:  neovim, vim-plugin
Vim Startify
šŸ”— The fancy start screen for Vim.
Stars: āœ­ 4,479 (+241.91%)
Mutual labels:  neovim, vim-plugin
Vista.vim
šŸŒµ Viewer & Finder for LSP symbols and tags
Stars: āœ­ 1,218 (-7.02%)
Mutual labels:  neovim, vim-plugin
Nnn.vim
File manager for vim/neovim powered by nĀ³
Stars: āœ­ 414 (-68.4%)
Mutual labels:  neovim, vim-plugin
Alchemist.vim
Elixir Integration Into Vim
Stars: āœ­ 632 (-51.76%)
Mutual labels:  neovim, vim-plugin
Lens.vim
A Vim Automatic Window Resizing Plugin
Stars: āœ­ 381 (-70.92%)
Mutual labels:  neovim, vim-plugin
Git Messenger.vim
Vim and Neovim plugin to reveal the commit messages under the cursor
Stars: āœ­ 904 (-30.99%)
Mutual labels:  neovim, vim-plugin
Dashboard Nvim
vim dashboard
Stars: āœ­ 294 (-77.56%)
Mutual labels:  neovim, vim-plugin
Rigel
šŸŒŒ Colorscheme for vim, terminal, vscode and slack - based on the star Rigel āœØ.
Stars: āœ­ 324 (-75.27%)
Mutual labels:  neovim, vim-plugin
Notational Fzf Vim
Notational velocity for vim.
Stars: āœ­ 975 (-25.57%)
Mutual labels:  neovim, vim-plugin
Vim Lookup
Jump to the definition of variables or functions in VimL code.
Stars: āœ­ 51 (-96.11%)
Mutual labels:  neovim, vim-plugin

vim-which-key

Introduction

vim-which-key is vim port of emacs-which-key that displays available keybindings in popup.

emacs-which-key started as a rewrite of guide-key, very likely, vim-which-key heavily rewrote vim-leader-guide. The features of vim-which-key has evolved a lot since then.


Vim config in the screenshot is space-vim.

Pros.

  • Better UI, vim's popup and neovim's floating_win are supported.
  • Show all mappings following a prefix, e.g., <leader>, <localleader>, etc.
  • Instant response for your every single input.
  • Dynamic update on every call.
  • Define group names and arbitrary descriptions.

Installation

Plugin Manager

Assuming you are using vim-plug:

Plug 'liuchengxu/vim-which-key'

" On-demand lazy load
Plug 'liuchengxu/vim-which-key', { 'on': ['WhichKey', 'WhichKey!'] }

" To register the descriptions when using the on-demand load feature,
" use the autocmd hook to call which_key#register(), e.g., register for the Space key:
" autocmd! User vim-which-key call which_key#register('<Space>', 'g:which_key_map')

For other plugin managers please refer to their document for more details.

Package management

Vim 8

$ mkdir -p ~/.vim/pack/git-plugins/start
$ git clone https://github.com/liuchengxu/vim-which-key.git --depth=1 ~/.vim/pack/git-plugins/start/vim-which-key

NeoVim

$ mkdir -p ~/.local/share/nvim/site/pack/git-plugins/start
$ git clone https://github.com/liuchengxu/vim-which-key.git --depth=1 ~/.local/share/nvim/site/pack/git-plugins/start/vim-which-key

Requirement

vim-which-key requires option timeout is on, see :h timeout.

Since timeout is on by default, all you need is not to set notimeout in your .vimrc.

Usage

timeoutlen

Let's say SPC is your leader key and you use it to trigger vim-which-key:

nnoremap <silent> <leader> :WhichKey '<Space>'<CR>

After pressing leader the guide buffer will pop up when there are no further keystrokes within timeoutlen.

" By default timeoutlen is 1000 ms
set timeoutlen=500

Pressing other keys within timeoutlen will either complete the mapping or open a subgroup. In the screenshot above SPCb will open up the buffer menu.

Please note that no matter which mappings and menus you configure, your original leader mappings will remain unaffected. The key guide is an additional layer. It will only activate, when you do not complete your input during the timeoutlen duration.

Special keys

  • Use BS to show the upper level mappings.

Configuration

Minimal Configuration

:WhichKey and :WhichKeyVisual are the primary way of interacting with this plugin.

Assuming your leader and localleader key are <Space> and ,, respectively, even no description dictionary has been registered, all <Space> and , related mappings will be displayed regardless.

let g:mapleader = "\<Space>"
let g:maplocalleader = ','
nnoremap <silent> <leader>      :<c-u>WhichKey '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey  ','<CR>

The raw content displayed is normally not adequate to serve as a cheatsheet. See the following section for configuring it properly.

If no description dictionary is available, the right-hand-side of all mappings will be displayed:

The dictionary configuration is necessary to provide group names or a description text.

let g:which_key_map['w'] = {
      \ 'name' : '+windows' ,
      \ 'w' : ['<C-W>w'     , 'other-window']          ,
      \ 'd' : ['<C-W>c'     , 'delete-window']         ,
      \ '-' : ['<C-W>s'     , 'split-window-below']    ,
      \ '|' : ['<C-W>v'     , 'split-window-right']    ,
      \ '2' : ['<C-W>v'     , 'layout-double-columns'] ,
      \ 'h' : ['<C-W>h'     , 'window-left']           ,
      \ 'j' : ['<C-W>j'     , 'window-below']          ,
      \ 'l' : ['<C-W>l'     , 'window-right']          ,
      \ 'k' : ['<C-W>k'     , 'window-up']             ,
      \ 'H' : ['<C-W>5<'    , 'expand-window-left']    ,
      \ 'J' : [':resize +5'  , 'expand-window-below']   ,
      \ 'L' : ['<C-W>5>'    , 'expand-window-right']   ,
      \ 'K' : [':resize -5'  , 'expand-window-up']      ,
      \ '=' : ['<C-W>='     , 'balance-window']        ,
      \ 's' : ['<C-W>s'     , 'split-window-below']    ,
      \ 'v' : ['<C-W>v'     , 'split-window-below']    ,
      \ '?' : ['Windows'    , 'fzf-window']            ,
      \ }

If you wish to hide a mapping from the menu set it's description to 'which_key_ignore'. Useful for instance, to hide a list of [1-9] window swapping mappings. For example the below mapping will not be shown in the menu.

nnoremap <leader>1 :1wincmd w<CR>
let g:which_key_map.1 = 'which_key_ignore'

If you want to hide a group of non-top level mappings, set the name to 'which_key_ignore'. For example,

nnoremap <leader>_a :echom '_a'<CR>
nnoremap <leader>_b :echom '_b'<CR>
let g:which_key_map['_'] = { 'name': 'which_key_ignore' }

Example

You can configure a Dict for each prefix so that the display is more readable.

To make the guide pop up Register the description dictionary for the prefix first. Assuming Space is your leader key and the Dict for configuring Space is g:which_key_map:

call which_key#register('<Space>', "g:which_key_map")

nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>

The next step is to add items to g:which_key_map:

" Define prefix dictionary
let g:which_key_map =  {}

" Second level dictionaries:
" 'name' is a special field. It will define the name of the group, e.g., leader-f is the "+file" group.
" Unnamed groups will show a default empty string.

" =======================================================
" Create menus based on existing mappings
" =======================================================
" You can pass a descriptive text to an existing mapping.

let g:which_key_map.f = { 'name' : '+file' }

nnoremap <silent> <leader>fs :update<CR>
let g:which_key_map.f.s = 'save-file'

nnoremap <silent> <leader>fd :e $MYVIMRC<CR>
let g:which_key_map.f.d = 'open-vimrc'

nnoremap <silent> <leader>oq  :copen<CR>
nnoremap <silent> <leader>ol  :lopen<CR>
let g:which_key_map.o = {
      \ 'name' : '+open',
      \ 'q' : 'open-quickfix'    ,
      \ 'l' : 'open-locationlist',
      \ }

" =======================================================
" Create menus not based on existing mappings:
" =======================================================
" Provide commands(ex-command, <Plug>/<C-W>/<C-d> mapping, etc.)
" and descriptions for the existing mappings.
"
" Note:
" Some complicated ex-cmd may not work as expected since they'll be
" feed into `feedkeys()`, in which case you have to define a decicated
" Command or function wrapper to make it work with vim-which-key.
" Ref issue #126, #133 etc.
let g:which_key_map.b = {
      \ 'name' : '+buffer' ,
      \ '1' : ['b1'        , 'buffer 1']        ,
      \ '2' : ['b2'        , 'buffer 2']        ,
      \ 'd' : ['bd'        , 'delete-buffer']   ,
      \ 'f' : ['bfirst'    , 'first-buffer']    ,
      \ 'h' : ['Startify'  , 'home-buffer']     ,
      \ 'l' : ['blast'     , 'last-buffer']     ,
      \ 'n' : ['bnext'     , 'next-buffer']     ,
      \ 'p' : ['bprevious' , 'previous-buffer'] ,
      \ '?' : ['Buffers'   , 'fzf-buffer']      ,
      \ }

let g:which_key_map.l = {
      \ 'name' : '+lsp',
      \ 'f' : ['spacevim#lang#util#Format()'          , 'formatting']       ,
      \ 'r' : ['spacevim#lang#util#FindReferences()'  , 'references']       ,
      \ 'R' : ['spacevim#lang#util#Rename()'          , 'rename']           ,
      \ 's' : ['spacevim#lang#util#DocumentSymbol()'  , 'document-symbol']  ,
      \ 'S' : ['spacevim#lang#util#WorkspaceSymbol()' , 'workspace-symbol'] ,
      \ 'g' : {
        \ 'name': '+goto',
        \ 'd' : ['spacevim#lang#util#Definition()'     , 'definition']      ,
        \ 't' : ['spacevim#lang#util#TypeDefinition()' , 'type-definition'] ,
        \ 'i' : ['spacevim#lang#util#Implementation()' , 'implementation']  ,
        \ },
      \ }

The guide will be up to date at all times. Native vim mappings will always take precedence over dictionary-only mappings.

It is possible to call the guide for keys other than leader:

nnoremap <localleader> :<c-u>WhichKey  ','<CR>
vnoremap <localleader> :<c-u>WhichKeyVisual  ','<CR>
  • Refer to space-vim for more detailed example.

Hide statusline

Since the theme of provided statusline is not flexible and all the information has been echoed already, I prefer to hide it.

autocmd! FileType which_key
autocmd  FileType which_key set laststatus=0 noshowmode noruler
  \| autocmd BufLeave <buffer> set laststatus=2 showmode ruler

Commands

See more details about commands and options via :h vim-which-key.

Command Description
:WhichKey {prefix} Open the guide window for the given prefix
:WhichKey! {dict} Open the guide window for a given dictionary directly

Options

Variable Default Description
g:which_key_vertical 0 show popup vertically
g:which_key_position botright split a window at the bottom
g:which_key_hspace 5 minimum horizontal space between columns
g:which_key_centered 1 make all keybindings centered in the middle

Credit

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].