nvim-telescope/telescope.nvim

Add Functionality to Delete Marks Directly from Telescope Marks Pane with `<C-d>`

danrasmuson opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
When using Telescope to view the marks in Neovim, currently there is no direct way to delete a mark from within the Telescope marks pane. I'm frustrated because I have to exit the pane and use the :delmarks command manually to remove unwanted marks.

Describe the solution you'd like
I would like to be able to hit <C-d> while in the Telescope marks pane to delete a highlighted mark instantly. This feature would streamline the process of managing marks by allowing users to organize them efficiently without breaking workflow or requiring extra keypresses.

Describe alternatives you've considered
One alternative would be to manually note the unwanted marks and use the :delmarks command after closing the Telescope pane. However, this does not provide the same level of convenience and interrupts the user's workflow. Another possibility is to implement a custom Telescope action that can be invoked to delete a mark.

Additional context
This feature would be in line with the existing design of Telescope, which is built to be a comprehensive and interactive tool for navigating various aspects of the Neovim environment. Allowing the deletion of marks directly from the interface would further contribute to its utility and user-friendliness.

We have a delete_mark action (:h telescope.actions.delete_mark()) that you can use for this.
It's just not bound to the marks picker by default. Maybe it should, I wouldn't be opposed to it but I don't think <C-d> would be a great one since that's already the default key for scrolling previews. I'm not sure what would be a good default key for it.

For yourself, you can do something like this to get this feature working today

require("telescope").setup({
  defaults = {
    -- .. default options
  },
  pickers = {
    marks = {
      attach_mappings = function(_, map)
        map({"i", "n"}, "<C-d>", require("telescope.actions").delete_mark)
        return true
      end,
    },
  },
})

edit: fixed the missing return true

Thanks you @jamestrew. Very helpful! Love it.

I had to make one adjustment to the snippet you provided. For me it was erroring this way...

CleanShot 2024-05-10 at 09 19 55@2x

But then I was able to adjust it too...

require("telescope").setup({
  defaults = {
    -- .. default options
  },
  pickers = {
    marks = {
      attach_mappings = function(prompt_bufnr, map)
        map("i", "<C-d>", function()
          require("telescope.actions").delete_mark(prompt_bufnr)
        end)
        return true -- Keep default mappings as well as the custom ones
      end,
    },
  },
})