Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packer "cond" alternaive #89

Closed
aloknigam247 opened this issue Dec 22, 2022 · 8 comments · Fixed by #166
Closed

Packer "cond" alternaive #89

aloknigam247 opened this issue Dec 22, 2022 · 8 comments · Fixed by #166
Labels
bug Something isn't working

Comments

@aloknigam247
Copy link

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

@aloknigam247 aloknigam247 added the bug Something isn't working label Dec 22, 2022
@folke
Copy link
Owner

folke commented Dec 22, 2022

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

@folke folke closed this as completed Dec 22, 2022
@shadmansaleh
Copy link

shadmansaleh commented Dec 23, 2022

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
Copy link

Congee commented Dec 24, 2022

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
Copy link
Owner

folke commented Dec 24, 2022

@Congee just use event="FileType" for this

@Congee
Copy link

Congee commented Dec 24, 2022

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

@folke
Copy link
Owner

folke commented Dec 24, 2022

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
Copy link

Congee commented Dec 24, 2022

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

@ju1ius
Copy link

ju1ius commented Dec 26, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants