Replies: 2 comments 5 replies
-
My current 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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " "
require("lazy").setup({
{"ellisonleao/gruvbox.nvim",
lazy = false,
};
{"sainnhe/gruvbox-material",
lazy = false,
};
{"numToStr/Comment.nvim",
lazy = false,
opts = {},
config = function(_, opts)
require("Comment").setup(opts)
end
};
{"nvim-tree/nvim-tree.lua",
lazy = false,
version = "*",
dependencies = { { "nvim-tree/nvim-web-devicons" } },
opts = {
sort_by = "case_sensitive",
renderer = {
group_empty = true,
special_files = {},
},
actions = { open_file = { quit_on_open = false } },
filters = { dotfiles = false, git_ignored = false, custom = { "^.DS_Store$", "^\\.git$" } },
git = { enable = true, ignore = true, timeout = 500 },
},
config = function(_, opts)
require("nvim-tree").setup(opts)
end
};
{"nvim-treesitter/nvim-treesitter-context"},
{"nvim-treesitter/nvim-treesitter",
lazy = true,
-- dependencies = {"nvim-treesitter/nvim-treesitter-textobjects"},
build = ":TSUpdate",
opts = {
sync_install = false, -- Install parsers synchronously (only applied to `ensure_installed`)
auto_install = false,
highlight = {
enable = true
},
indent = {
enable = false
},
incremental_selection = {
enable = true,
additional_vim_regex_highlighting = false,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
else
return false
end
end,
},
},
config = function(_, opts)
require('nvim-treesitter.configs').setup({opts})
end
};
{"nvim-telescope/telescope.nvim",
lazy = false,
dependencies = {
{"nvim-lua/plenary.nvim"},
{"nvim-telescope/telescope-fzf-native.nvim",
build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build"
},
{"sharkdp/fd"}
},
branch = "0.1.x",
};
{"windwp/nvim-autopairs" ,
lazy = false,
opts = {},
config = function(_, opts)
require("nvim-autopairs").setup({opts})
end
},
-- LSP installer
{ "williamboman/mason.nvim",
lazy = true,
cmd = {"Mason", "MasonInstall", "MasonInstallAll", "MasonUninstall", "MasonUninstallAll", "MasonLog"},
opts = {
PATH = "prepend",
ui = {
keymaps = {
toggle_server_expand = "<CR>",
install_server = "i",
update_server = "u",
check_server_version = "c",
update_all_servers = "U",
check_outdated_servers = "C",
uninstall_server = "X",
cancel_installation = "<C-c>"
}
},
max_concurrent_installers = 10
},
config = function(_, opts)
require("mason").setup(opts)
end
},
-- LSP config
{"neovim/nvim-lspconfig",
lazy = true,
event = {"BufReadPre", "BufNewFile"},
dependencies = {
{"williamboman/mason.nvim"},
{"williamboman/mason-lspconfig.nvim"},
{"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"saadparwaiz1/cmp_luasnip",
"L3MON4D3/LuaSnip",
}
}
},
opts = {
autoformat = false,
format = {
formatting_options = nil,
timeout_ms = nil
},
-- LSP Server Settings
servers = {
fortls = {},
clangd = {},
},
},
config = function(_, opts)
local luasnip = require("luasnip");
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-b>'] = cmp.mapping.select_prev_item(),
['<C-u>'] = cmp.mapping.scroll_docs(-2),
['<C-d>'] = cmp.mapping.scroll_docs(2),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = "buffer" },
{ name = "path" },
})
})
local servers = opts.servers
local keymap_set = vim.keymap.set;
local on_attach = function(_, bufnr)
local nnoremap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
keymap_set('n', keys, func, { buffer = bufnr, noremap = true, desc = desc });
end
nnoreamp('<leader>dm', vim.diagnostic.open_float, 'Open floating [d]iagnostic [m]essage' )
nnoreamp("gp", vim.diagnostic.goto_prev, '[G]o to [p]revious diagnostic message' )
nnoreamp("gn", vim.diagnostic.goto_next, '[G]o to [n]ext diagnostic message' )
nnoreamp('<leader>dl', vim.diagnostic.setloclist, 'Open [d]iagnostics [l]ist' )
nnoremap('gd', vim.lsp.buf.definition, '[G]oto [d]efinition')
nnoremap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nnoremap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
nnoremap('gr', vim.lsp.buf.references, '[G]oto [R]eferences')
nnoremap('K', vim.lsp.buf.hover, 'Hover documentation')
nnoremap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
nnoremap('<space>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nnoremap('<space>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nnoremap('<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, 'List [W]orkspace [F]olders')
nnoremap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nnoremap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
nnoremap('<leader>f', function()
vim.lsp.buf.format { async = true }
end, 'Format current buffer')
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action,
{buffer = bufnr, noremap = true, desc = 'LSP: [C]ode [A]ction'})
end
local lspconfig = require("lspconfig");
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
local function setup(server_name)
local server_opts = {
capabilities = capabilities,
on_attach = on_attach,
-- filetypes = (servers[server] or {}).filetypes,
}
lspconfig[server_name].setup(server_opts)
end
local mlsp = require("mason-lspconfig")
local available = mlsp.get_available_servers()
local ensure_installed = {} ---@type string[]
for server, server_opts in pairs(servers) do
if server_opts then
server_opts = server_opts == true and {} or server_opts
-- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
if server_opts.mason == false or not vim.tbl_contains(available, server) then
setup(server)
else
ensure_installed[#ensure_installed + 1] = server
end
end
end
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = ensure_installed,
automatic_installation = true
})
require("mason-lspconfig").setup_handlers({setup})
end
},
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Indeed, many of the plugins are not lazy-loaded. But, if I do lazy-load them, I don't really know how to actually load them.. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone reading this.
I am really struggling understanding how to optimally setup Lazy, and fully unlock its potential.
In the
README.md
it is stated"My config for example loads in about 11ms with 93 plugins. I do a lot of lazy-loading though :)"
Could someone show an example of such configuration?
Because, my startup time is much higher, and some functionalities do not even work at all..
I would only need the basic, i.e. nvim-tree, telescope, treesitter, and basic LSP.
Any answer/guidance would be more than welcome!
Beta Was this translation helpful? Give feedback.
All reactions