Skip to content
Open
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
35 changes: 35 additions & 0 deletions lua/cheatsheet/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ M.pick_cheat = function(telescope_opts, opts)
return
end

-- Extract command from cheat, eg:
-- ":%bdelete" -> No change
-- ":set hls!" -> No change
-- ":edit [file]" -> ":edit "
-- ":set shiftwidth={n}" -> ":set shiftwidth="
local command = cheat:match("^:[^%[%{]+")
if command ~= nil then
vim.api.nvim_exec(command, true)
else
vim.api.nvim_echo(
{ -- text, highlight group
{ "Cheatsheet [", "" },
{ section, "cheatMetadataSection" },
{ "]: Press ", "" }, { cheat, "cheatCode" },
{ " to ", "" },
{ description:lower(), "cheatDescription" },
}, false, {}
)
end
end
)
map(
'i', '<C-r>', function()
local selection = actions_state.get_selected_entry()
local section = selection.value.section
local description = selection.value.description
local cheat = selection.value.cheatcode

actions.close(prompt_bufnr)

if string.len(cheat) == 1 then
print("Cheatsheet: No command could be executed")
return
end

-- Extract command from cheat, eg:
-- ":%bdelete" -> No change
-- ":set hls!" -> No change
Expand Down