telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Ability to set a theme as default value

Open amirrezaask opened this issue 3 years ago • 11 comments

Is your feature request related to a problem? Please describe. I want to set a theme ( for example ivy ) as the default theme in telescope.setup

Describe the solution you'd like require("telescope").setup({theme = 'ivy' })

amirrezaask avatar May 16 '21 14:05 amirrezaask

Is your feature request related to a problem? Please describe. I want to set a theme ( for example ivy ) as the default theme in telescope.setup

Describe the solution you'd like require("telescope").setup({theme = 'ivy' })

Why don't you create a new function, set it to use the theme you want, and possibly add options different from the default (the rest of the options will be inherited from the default), bind the function to some key or command.

local open_dir = function(config)
    local opt = require('telescope.themes').get_ivy {
        cwd = config.dir,
        prompt_title = config.title,
        shorten_path = true
    }
    require('telescope.builtin').find_files(opt)
end

medwatt avatar May 16 '21 17:05 medwatt

Thank you for tour help, i created a small function to wrap my calls to telescope and add theme options to it so i think i dont need a builtin thing yet i think it would help if such feature exists

amirrezaask avatar May 17 '21 12:05 amirrezaask

I ran across this issue and wondered why there still isn't an option for setting the default theme? We have them for layouts and numerous other configurations, it would only make sense to add one for themes?

Maybe this issue should be reopened?

ok-nick avatar Aug 21 '22 18:08 ok-nick

Agreed, this would make the config cleaner

tomasmota avatar Nov 30 '22 10:11 tomasmota

Just ran into same, couldn't figure out why setting as default didn't take and was wondering if I really had to set it for each individual picker. Turns out I do.

I appreciate very often keys and functions will be assigned, in which case this option can be passed. That still requires each picker to be set-up individually

I'd like it if any time, any ":Telescope somepicker" was ran it would use a default theme.

For now I am going to do pickers = { ={theme="ivy")) for each picker available

Would make config cleaner if we could do { defaults = {theme="ivy}}

rolflobker avatar Feb 20 '23 19:02 rolflobker

yeah this issue should have been reopened, we need to find a suitable solution for this issue.

Conni2461 avatar Feb 20 '23 21:02 Conni2461

After snooping around in the source files, turns out the themes set layout options which can be set as default. I was unaware of this. Doing it this way does greatly reduces config.

This did the trick for me:

defaults = { layout_strategy = 'bottom_pane', layout_config = { height = 0.4, }, border = true, sorting_strategy = "ascending", [..] }

Still would probably make more sense to allow setting a 'theme' in defaults which would result in even "cleaner" code:

defaults = { theme = "ivy", [..] }

The latter just "feels right"

rolflobker avatar Feb 21 '23 06:02 rolflobker

@rolflobker thanks for pointing that out.

Instead of copy-pasting the theme's options, you could also import it into your defaults table, like so:

telescope.setup({
  defaults = vim.tbl_extend(
      "force",
      require('telescope.themes').get_dropdown(), -- or get_cursor, get_ivy
      {
        --- your own `default` options go here, e.g.:
        path_display = {
          truncate = 2
        },
        mappings = {
          i = {
            ["<esc>"] = actions.close,
          },
        }
      }
  ),
  extensions = {},
  [...]
})

This way you don't have to update your config if a the upstream theme is changed.

I do however fully agree that it would be so much better to be able to set

telescope.setup({
 defaults = {
  theme = "dropdown", -- Or whatever theme you like
},

bartvanraaij avatar Jun 09 '23 09:06 bartvanraaij

I found it a bit annoying that no default config is possible but I have a much easier workaround. This is an exceprt from my kmp.lua, which contains all my keymaps and at the top of which kym is already aliased to vim.keymap.set()

--telescope
local ivy = require('telescope.themes').get_ivy()
kym('n', '<leader>ff', function() require('telescope.builtin').find_files(ivy) end )
kym('n', '<leader>fs', function() require('telescope.builtin').live_grep(ivy) end )--string cwd
kym('n', '<leader>ft', function() require('telescope.builtin').treesitter(ivy) end )--find symbol
...

As you can see only a single line is added to the config, using the keybindings you already have.

Rydwxz avatar Jul 18 '23 04:07 Rydwxz

I came up with a similar solution but because I personally do not like the clutter of making an anonymous function inline, I made a wrapper:

local function theme_wrapper(telescope_command)
  return function()
    telescope_command(require("telescope.themes").get_dropdown())
  end
end

then things become:

{ "<leader>sh", theme_wrapper(builtin.help_tags), desc = "Help Pages" }

tudorjnu avatar Mar 10 '24 07:03 tudorjnu

require('telescope').setup({
  defaults = require('telescope.themes').get_dropdown(),
})

rodrigo-sys avatar Jul 18 '24 21:07 rodrigo-sys