Skip to content

Commit

Permalink
feat: preset with misc keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Apr 28, 2021
1 parent df49a59 commit e610338
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 33 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

* [x] hook into all groups
* [x] show mappings without keymap (zz etc)
* [ ] plugin support for marks, registers, text objects
* [x] plugin support for marks, registers, text objects
* [x] `<bs>` to go up a level
* [ ] config modes
* [x] update buf only
* [x] + thingy for groups
* [x] text objects
* [x] get label from global when not found for buffer
* [ ] configurable timeout
* [x] operators & motions
* [ ] show window after timeout?
* [x] make plugins a list of key value with config in value
* [x] cleanup text objects text
* [x] buf local mappings seems to interfer with global mappings (push K in help)
* [x] fix help in visual mode
23 changes: 0 additions & 23 deletions lua/which-key/builtin.lua

This file was deleted.

1 change: 1 addition & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local defaults = {
["text-objects"] = true,
operators = true,
motions = true,
misc = { windows = true, nav = true, z = true, g = true },
},
window = {
border = "none", -- none, single, double, shadow
Expand Down
8 changes: 0 additions & 8 deletions lua/which-key/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ local M = {}

function M.setup(options)
config.setup(options)
if config.options.builtin then M.register(require("which-key.builtin")) end
if config.options.plugins.marks then M.register_plugin(require("which-key.plugins.marks")) end
if config.options.plugins.registers then
M.register_plugin(require("which-key.plugins.registers"))
end
if config.options.plugins.text_objects then
M.register_plugin(require("which-key.plugins.text-objects"))
end
Plugin.setup()
end

Expand Down
3 changes: 2 additions & 1 deletion lua/which-key/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function M.setup()
local opts = Config.options.plugins[name]
if opts == nil then opts = { enabled = false } end
if type(opts) == "boolean" then opts = { enabled = opts } end
opts.enabled = opts.enabled ~= false
if opts.enabled then
if type(plugin) == "string" then
plugin = require(plugin)
Expand Down Expand Up @@ -60,7 +61,7 @@ function M.invoke(results)
end

-- Register builtin plugins
local builtin = { "marks", "registers", "text-objects", "operators", "motions" }
local builtin = { "marks", "registers", "text-objects", "operators", "motions", "misc" }
for _, name in pairs(builtin) do M.register("which-key.plugins." .. name, name) end

return M
84 changes: 84 additions & 0 deletions lua/which-key/plugins/misc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
local M = {}

M.name = "misc"

local misc = {
windows = {
["<c-w>"] = {
name = "window",
s = "Split window",
v = "Split window vertically",
w = "Switch windows",
q = "Quit a window",
T = "Break out into a new tab",
x = "Swap current with next",
["-"] = "Decrease height",
["+"] = "Increase height",
["<lt>"] = "Decrease width",
[">"] = "Increase width",
["|"] = "Max out the width",
["="] = "Equally high and wide",
h = "Go to the left window",
l = "Go to the right window",
k = "Go to the up window",
j = "Go to the down window",
},
},
z = {
["z"] = {
o = "Open fold under cursor",
O = "Open all folds under cursor",
c = "Close fold under cursor",
C = "Close all folds under cursor",
a = "Toggle fold under cursor",
A = "Toggle all folds under cursor",
v = "Show cursor line",
M = "Close all folds",
R = "Open all folds",
m = "Fold more",
r = "Fold less",
x = "Update folds",
z = "Center this line",
t = "Top this line",
b = "Bottom this line",
g = "Add word to spell list",
w = "Mark word as bad/misspelling",
},
},
nav = {
["[{"] = "Previous {",
["[("] = "Previous (",
["[<"] = "Previous <",
["[m"] = "Previous method start",
["[M"] = "Previous method end",
["[%"] = "Previous unmatched group",
["[s"] = "Previous misspelled word",
["]{"] = "Next {",
["]("] = "Next (",
["]<lt>"] = "Next <",
["]m"] = "Next method start",
["]M"] = "Next method end",
["]%"] = "Next unmatched group",
["]s"] = "Next misspelled word",
["H"] = "Home line of window (top)",
["M"] = "Middle line of window",
["L"] = "Last line of window",
},
g = {
["gf"] = "Got to file under cursor",
["gx"] = "Open the file under cursor with system app",
["gi"] = "Move to the last insertion and INSERT",
["gv"] = "Switch to VISUAL using last selection",
["gn"] = "Search forwards and select",
["gN"] = "Search backwards and select",
["g%"] = "Cycle backwards through results",
},
}

function M.setup(wk, config)
for key, mappings in pairs(misc) do
if config[key] ~= false then wk.register(mappings, { mode = "n", prefix = "" }) end
end
end

return M

0 comments on commit e610338

Please sign in to comment.