Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Plugin | Description
[`linecopypaste`](plugins/linecopypaste.lua?raw=1) | Copy, cut and paste the current line when nothing is selected
[`lineguide`](plugins/lineguide.lua?raw=1) | Displays a line-guide at the line limit offset *([screenshot](https://user-images.githubusercontent.com/3920290/81476159-2cf70000-9208-11ea-928b-9dae3884c477.png))*
[`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages
[`listkeybindings`](plugins/listkeybindings.lua?raw=1) | Dump all defined key bindings to a new document
[`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt`
[`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))*
[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
Expand Down
90 changes: 90 additions & 0 deletions plugins/listkeybindings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
--[[
listkeybindings.lua
creates a new document and lists all key-bindings
version: 20200627_152637
originally by SwissalpS

show-key-binding will list key first then binding
show-binding-key will list binding first then key

If sort plugin is installed, the list will also be sorted.
--]]
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"

local function pasteAndSort(sOut)
core.root_view:open_doc(core.open_doc())
core.active_view.doc:text_input(sOut)
if command.map['sort:sort'] then
command.perform('doc:select-all')
command.perform('sort:sort')
command.perform('doc:select-none')
end
end

local function gatherLists()

local lKeys = {}
local lBindings = {}
local iLongestKey = 0
local iLongestBinding = 0
local iIndex = 0

for k, v in pairs(keymap.map) do
if iLongestKey < #k then iLongestKey = #k end
for _, x in ipairs(v) do
iIndex = iIndex + 1
if iLongestBinding < #x then iLongestBinding = #x end
lKeys[iIndex] = k
lBindings[iIndex] = x
end
end

return lKeys, lBindings, iLongestKey, iLongestBinding

end -- gatherLists

local function listBindingsKey()

local sOut = ''
local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists()

-- format pretty output
local sSpace, k, v
local iLongest = iLongestBinding + 1
for i = 1, #lKeys, 1 do
k = lBindings[i]
v = lKeys[i]
sSpace = string.rep(' ', iLongest - #k)
sOut = sOut .. k .. sSpace .. v .. '\n'
end

pasteAndSort(sOut)

end

local function listKeyBindings()

local sOut = ''
local lKeys, lBindings, iLongestKey, iLongestBinding = gatherLists()

-- format pretty output
local sSpace, k, v
local iLongest = iLongestKey + 1
for i = 1, #lKeys, 1 do
v = lBindings[i]
k = lKeys[i]
sSpace = string.rep(' ', iLongest - #k)
sOut = sOut .. k .. sSpace .. v .. '\n'
end

pasteAndSort(sOut)

end

command.add("core.docview", {
["listkeybindings:show-key-binding"] = listKeyBindings,
["listkeybindings:show-binding-key"] = listBindingsKey,
})