folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
13.96k stars 335 forks source link

Packer "cond" alternaive #89

Closed aloknigam247 closed 1 year ago

aloknigam247 commented 1 year ago

Any alternative to cond in packer: my packer config usecase

use {
    'ojroques/vim-oscyank',
    cond = function()
        -- Check if connection is ssh
        return os.getenv("SSH_CLIENT") ~= nil
    end,
    config = function()
        vim.cmd[[autocmd TextYankPost * if v:event.operator is 'y' && v:event.regname is '' | execute 'OSCYankReg "' | endif]]
    end
}

load vim-oscyank only when connected via SSH

folke commented 1 year ago

You can use enabled for that. It can be a function like your cond()

shadmansaleh commented 1 year ago

You can use enabled for that. It can be a function like your cond()

if the enabled function returns false lazy marks the plugins for clean. so if user runs clean or sync they'll be deleted. cond doesn't do that. I think that was the distinction between cond and disabled in packer.

I had it set so if NOTS env set nothing related to tree-sitter gets loaded. in packer it was handled by cond. in lazy I'm reinstalling all the treesitter-related and dependent plugins plus all the parsers :/ . It'd be nice to avoid that.

Congee commented 1 year ago

Another difference is cond can evaluate filetype after that file is loaded, while, enabled evaluates too early.

I have vim-polyglot enabled when the current buffer isn't empty. This will always evaluate to false no matter what the filetype is :/

enabled = function()
    return vim.bo.filetype ~= '';
end,

(not relevant to this issue, it would be helpful if lazy.nvim could load a plugin when the filetype is NOT a given table or string)

folke commented 1 year ago

@Congee just use event="FileType" for this

Congee commented 1 year ago

Ahh thanks, I was using event="VeryLazy" 😃

folke commented 1 year ago

Be aware, that a of of plugins set filetypes like noice, notify, lualine, etc, so that will pretty much make it load on startup anyway.

Better would be event="BufReadPre". That will only kick in when an actual file is being read.

Congee commented 1 year ago

Interesting, I switched to "BufReadPre". thanks for the pro tip 😁

ju1ius commented 1 year ago

@folke Another use case for this feature is when using neovim inside VSCode.

In that case, you want your treesitter, LSP, colorscheme, statusline, etc... plugins to load only when not running inside vscode but you don't want your plugin manager to uninstall/reinstall everything each time you switch editors. With packer you can do that with e.g.:

use {
  'nvim-treesitter/nvim-treesitter',
  cond = [[not vim.g.vscode]],
}

As @shadmansaleh mentioned, enabled is not equivalent to packer's cond or vim-plug's Cond function.

It would be nice if lazy could support this feature.