nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.37k stars 823 forks source link

Ability to set a theme as default value #848

Open amirrezaask opened 3 years ago

amirrezaask commented 3 years ago

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' })

medwatt commented 3 years ago

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
amirrezaask commented 3 years ago

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

ok-nick commented 2 years ago

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?

tomasmota commented 1 year ago

Agreed, this would make the config cleaner

rolflobker commented 1 year ago

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}}

Conni2461 commented 1 year ago

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

rolflobker commented 1 year ago

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"

bartvanraaij commented 1 year ago

@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
},
Rydwxz commented 1 year ago

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.

tudorjnu commented 6 months ago

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" }
rodrigo-sys commented 1 month ago
require('telescope').setup({
  defaults = require('telescope.themes').get_dropdown(),
})