NeoVim from Packer to Lazy

2.5k views Asked by At

I am currently starting my first project and i wanted to use NeoVim to learn it from scratch and to be faster in the future. I watched the video from theprimeagen "0 to LSP", but his built is not up to date, f. ex. his lsp.lua file doesn´t work. I also wanted to switch from packer to lazy.

First, i tried to make a switch from packer to lazy, because in my research, i found out that this would be better.I changed the packer file from primeagen to a new lazy file with the following code:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable",
        lazypath
    })
end

vim.opt.rtp:prepend(lazypath)

local plugins = {
    'wbthomason/packer.nvim',
    {
        'nvim-telescope/telescope.nvim',
        tag = '0.1.0',
        dependencies = { 'nvim-lua/plenary.nvim' }
    },
    {
        'rose-pine/neovim',
        as = 'rose-pine',
        config = function()
            vim.cmd('colorscheme rose-pine')
        end
    },
    {
        "folke/trouble.nvim",
        config = function()
            require("trouble").setup {
                icons = false,
                -- Ihre Konfiguration hier
            }
        end
    },
    {
        'nvim-treesitter/nvim-treesitter',
        run = function()
            local ts_update = require('nvim-treesitter.install').update({ with_sync = true })
            ts_update()
        end
    },
    "nvim-treesitter/playground",
    "theprimeagen/harpoon",
    "theprimeagen/refactoring.nvim",
    "mbbill/undotree",
    "tpope/vim-fugitive",
    "nvim-treesitter/nvim-treesitter-context",
    'VonHeikemen/lsp-zero.nvim',
    branch = 'v1.x',
    dependencies = {
        -- LSP Support
        'neovim/nvim-lspconfig',
        'williamboman/mason.nvim',
        'williamboman/mason-lspconfig.nvim',
        -- Autocompletion
        'hrsh7th/nvim-cmp',
        'hrsh7th/cmp-buffer',
        'hrsh7th/cmp-path',
        'saadparwaiz1/cmp_luasnip',
        'hrsh7th/cmp-nvim-lsp',
        'hrsh7th/cmp-nvim-lua',
        -- Snippets
        'L3MON4D3/LuaSnip',
        'rafamadriz/friendly-snippets',
    }
}

local opts = {
    -- Ihre Konfigurationsoptionen hier
}

require("lazy").setup(plugins, opts)

Can someone tell me why this doesn´t work? And could someone recommend me a NeoVim built?

Thx in Advance :)

1

There are 1 answers

0
Andrés Silva On

You should try Kickstart Nvim, it's what I did when I started using Lazy because it gives you a very basic config. It's just easier to set your own config based on Kickstart because it gives you just what you need to start with a useful Neovim editor, as opposite to other distros, which gives you yet another editor (just my opinion).

This is my Neovim config, feel free to clone it, it's not perfect, but it works very well for me. I'm using Lazy and following the spec approach to define plugins.

Now, there are a couple of things that you have to change:

  1. Remove the Packer plugin, you won't need it anymore since you are using Lazy.
  2. Follow the Migration Guide in https://github.com/folke/lazy.nvim, because there are some keywords that have different names or merged.
  3. The dependencies key needs to be defined per plugin. If you are migrating from packer, basically is what you have as requires.
  4. In the color scheme plugin, I have this:
  {
    'rose-pine/neovim',
    name = 'rose-pine',
    lazy = false,
    priority = 1000,
    opts = {
      disable_background = true,
    },
    config = function()
      local p = require('rose-pine.palette')

      vim.cmd.colorscheme('rose-pine')
      vim.api.nvim_set_hl(0, 'Normal', { bg = 'none' })
      vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'none' })
      vim.api.nvim_set_hl(0, 'String', { fg = p.rose })
      vim.api.nvim_set_hl(0, 'Number', { fg = p.rose })
      vim.api.nvim_set_hl(0, 'Float', { fg = p.rose })
      vim.api.nvim_set_hl(0, 'Constant', { fg = p.rose })
      vim.api.nvim_set_hl(0, 'Character', { fg = p.rose })
    end,
  },

Instead of as, use name.

lazy = false and priority = 1000 to load it from startup.

In the config function, the important one is the vim.cmd.colorscheme('rose-pine'), which will set the color scheme to be loaded.

The rest of settings inside the config function are just to get rid of most of the gold colors in those groups.

  1. I don't know if it's required, but you should try to set each plugin as a table:
{
  'tpope/vim-fugitive',
  event = 'BufWinEnter',
},

The BufWinEnter event ensures Fugitive to be loaded as soon as you enter a buffer. https://neovim.io/doc/user/autocmd.html#BufWinEnter

I hope this helps you.