feat: Add built-in to search keymaps (#191)

* Add built-in to search keymaps

* Re-factor maps for cleaner codes

Rather than use function to return a results table for various key maps.
Assign results the key maps table itself. This makes for cleaner code.

* Keymaps: escape termcodes using built-in util

* Rename builtin.maps to builtin.keymaps
This commit is contained in:
Carlos Hernandez
2020-11-14 12:38:21 -07:00
committed by GitHub
parent 24057365da
commit 3c2dea3ea5
2 changed files with 36 additions and 0 deletions

View File

@@ -345,6 +345,13 @@ require'telescope.builtin'.command_history{}
Search the vim command history.
```lua
require'telescope.builtin.maps{}
```
Search on vim key maps.
```lua
require'telescope.builtin'.buffers{
-- Optional

View File

@@ -923,4 +923,33 @@ builtin.marks = function(opts)
}):find()
end
-- find normal mode mappings
builtin.keymaps = function(opts)
opts = opts or {}
local modes = {"n", "i", "c"}
local keymaps_table = {}
for _, mode in pairs(modes) do
local keymaps_iter = vim.api.nvim_get_keymap(mode)
for _, keymap in pairs(keymaps_iter) do
table.insert(keymaps_table, keymap)
end
end
pickers.new({}, {
prompt_title = 'Key Maps',
finder = finders.new_table {
results = keymaps_table,
entry_maker = function(line)
return {
valid = line ~= "",
value = line,
ordinal = line.lhs .. line.rhs,
display = line.mode .. ' ' .. utils.display_termcodes(line.lhs) .. ' ' .. line.rhs
}
end
},
sorter = conf.generic_sorter()
}):find()
end
return builtin