2024-03-22 09:15:09 +01:00
_G.LazyVim = require ( " lazyvim.util " )
2024-03-20 17:26:47 +01:00
2023-10-04 10:43:44 +02:00
---@class LazyVimConfig: LazyVimOptions
2023-01-10 10:07:19 +01:00
local M = { }
2025-02-08 15:37:13 +01:00
M.version = " 14.11.0 " -- x-release-please-version
2024-03-29 09:45:31 +01:00
LazyVim.config = M
2023-10-11 15:25:29 +02:00
2023-10-04 10:43:44 +02:00
---@class LazyVimOptions
2023-01-10 10:07:19 +01:00
local defaults = {
2023-01-10 10:44:10 +01:00
-- colorscheme can be a string like `catppuccin` or a function that will load the colorscheme
---@type string|fun()
colorscheme = function ( )
require ( " tokyonight " ) . load ( )
end ,
2023-02-11 08:59:42 +01:00
-- load the default settings
defaults = {
autocmds = true , -- lazyvim.config.autocmds
keymaps = true , -- lazyvim.config.keymaps
2023-04-16 11:34:35 +02:00
-- lazyvim.config.options can't be configured here since that's loaded before lazyvim setup
-- if you want to disable loading options, add `package.loaded["lazyvim.config.options"] = true` to the top of your init.lua
2023-02-11 08:59:42 +01:00
} ,
2023-10-12 14:38:25 +02:00
news = {
-- When enabled, NEWS.md will be shown when changed.
-- This only contains big new features and breaking changes.
lazyvim = true ,
-- Same but for Neovim's news.txt
neovim = false ,
} ,
2023-01-10 10:44:10 +01:00
-- icons used by other plugins
2023-10-11 22:38:38 +02:00
-- stylua: ignore
2023-01-10 10:07:19 +01:00
icons = {
2023-10-03 14:56:28 +02:00
misc = {
dots = " " ,
} ,
2024-06-06 10:43:18 +02:00
ft = {
octo = " " ,
} ,
2023-04-16 21:35:38 +02:00
dap = {
2023-10-11 22:38:38 +02:00
Stopped = { " " , " DiagnosticWarn " , " DapStoppedLine " } ,
Breakpoint = " " ,
2023-04-16 21:35:38 +02:00
BreakpointCondition = " " ,
2023-10-11 22:38:38 +02:00
BreakpointRejected = { " " , " DiagnosticError " } ,
LogPoint = " .> " ,
2023-04-16 21:35:38 +02:00
} ,
2023-01-10 10:07:19 +01:00
diagnostics = {
Error = " " ,
2023-10-11 22:38:38 +02:00
Warn = " " ,
Hint = " " ,
Info = " " ,
2023-01-10 10:07:19 +01:00
} ,
git = {
2023-10-11 22:38:38 +02:00
added = " " ,
2023-01-10 10:07:19 +01:00
modified = " " ,
2023-10-11 22:38:38 +02:00
removed = " " ,
2023-01-10 10:07:19 +01:00
} ,
kinds = {
2023-10-11 22:38:38 +02:00
Array = " " ,
Boolean = " " ,
Class = " " ,
Codeium = " " ,
Color = " " ,
Control = " " ,
Collapsed = " " ,
Constant = " " ,
Constructor = " " ,
Copilot = " " ,
Enum = " " ,
EnumMember = " " ,
Event = " " ,
Field = " " ,
File = " " ,
Folder = " " ,
Function = " " ,
Interface = " " ,
Key = " " ,
Keyword = " " ,
Method = " " ,
Module = " " ,
Namespace = " " ,
Null = " " ,
Number = " " ,
Object = " " ,
Operator = " " ,
Package = " " ,
Property = " " ,
Reference = " " ,
2024-12-15 08:27:03 +01:00
Snippet = " " ,
2023-10-11 22:38:38 +02:00
String = " " ,
Struct = " " ,
2024-11-13 17:49:47 +01:00
Supermaven = " " ,
2023-10-15 00:25:06 +08:00
TabNine = " " ,
2023-10-11 22:38:38 +02:00
Text = " " ,
2023-01-10 10:07:19 +01:00
TypeParameter = " " ,
2023-10-11 22:38:38 +02:00
Unit = " " ,
Value = " " ,
Variable = " " ,
2023-01-10 10:07:19 +01:00
} ,
} ,
2023-10-15 22:34:42 +02:00
---@type table<string, string[]|boolean>?
2023-10-12 00:09:04 +02:00
kind_filter = {
default = {
" Class " ,
" Constructor " ,
" Enum " ,
" Field " ,
" Function " ,
" Interface " ,
" Method " ,
" Module " ,
2023-10-12 11:14:23 +02:00
" Namespace " ,
" Package " ,
2023-10-12 00:09:04 +02:00
" Property " ,
" Struct " ,
" Trait " ,
} ,
2023-10-15 22:34:42 +02:00
markdown = false ,
help = false ,
2023-10-12 00:09:04 +02:00
-- you can specify a different filter for each filetype
2023-10-12 11:14:23 +02:00
lua = {
" Class " ,
" Constructor " ,
" Enum " ,
" Field " ,
" Function " ,
" Interface " ,
" Method " ,
" Module " ,
" Namespace " ,
-- "Package", -- remove package since luals uses it for control flow structures
" Property " ,
" Struct " ,
" Trait " ,
} ,
2023-10-12 00:09:04 +02:00
} ,
2023-01-10 10:07:19 +01:00
}
2023-10-11 17:47:16 +02:00
M.json = {
2025-02-08 15:23:30 +01:00
version = 8 ,
loaded = false ,
2024-06-29 21:19:13 +02:00
path = vim.g . lazyvim_json or vim.fn . stdpath ( " config " ) .. " /lazyvim.json " ,
2023-10-11 17:47:16 +02:00
data = {
2025-02-08 15:23:30 +01:00
version = nil , ---@type number?
install_version = nil , ---@type number?
2023-10-12 17:48:49 +02:00
news = { } , ---@type table<string, string>
2023-10-11 17:47:16 +02:00
extras = { } , ---@type string[]
} ,
}
function M . json . load ( )
2025-02-08 15:23:30 +01:00
M.json . loaded = true
2024-06-29 21:19:13 +02:00
local f = io.open ( M.json . path , " r " )
2023-10-11 17:47:16 +02:00
if f then
local data = f : read ( " *a " )
f : close ( )
local ok , json = pcall ( vim.json . decode , data , { luanil = { object = true , array = true } } )
if ok then
M.json . data = vim.tbl_deep_extend ( " force " , M.json . data , json or { } )
2023-10-12 21:45:32 +02:00
if M.json . data.version ~= M.json . version then
2024-03-22 09:15:09 +01:00
LazyVim.json . migrate ( )
2023-10-12 17:48:49 +02:00
end
2023-10-11 17:47:16 +02:00
end
2025-02-08 15:23:30 +01:00
else
M.json . data.install_version = M.json . version
2023-10-11 17:47:16 +02:00
end
end
2023-10-04 10:43:44 +02:00
---@type LazyVimOptions
2023-01-10 10:07:19 +01:00
local options
perf(core): defer clipboard because xsel and pbcopy can be slow (#4120)
## Description
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
See [this](https://github.com/LazyVim/LazyVim/discussions/4112)
discussion
TLDR:
Startup time performance is affected quite significantly when the
clipboard provider is `xsel`(linux) or `pbcopy`(macos). I expect an
improvement in these cases, especially on older pc's.
This PR resets `vim.opt.clipboard` after the `options` are loaded. Then,
on `VeryLazy`, the setting is restored.
I also tested with `yanky`.
Relevant prints:
1. Before resetting `vim.opt.clipboard` in `init`,
`vim.print(vim.opt.clipboard)` yields a table which will be captured:
```lua
--- fields
_name = "clipboard",
_value = "unnamedplus",
--- more fields
```
2. Set `vim.opt.clipboard = ""` and `vim.print(vim.opt.clipboard)`, also
yields a table:
```lua
--- fields
_name = "clipboard",
_value = "",
--- more fields
```
## Related Issue(s)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
Co-authored-by: abeldekat <abel@nomail.com>
2024-07-20 11:48:11 +02:00
local lazy_clipboard
2023-01-10 10:07:19 +01:00
2023-10-04 10:43:44 +02:00
---@param opts? LazyVimOptions
2023-01-10 10:07:19 +01:00
function M . setup ( opts )
2023-10-04 10:43:44 +02:00
options = vim.tbl_deep_extend ( " force " , defaults , opts or { } ) or { }
2023-10-01 14:18:22 +02:00
2023-09-26 10:57:41 +02:00
-- autocmds can be loaded lazily when not opening a file
local lazy_autocmds = vim.fn . argc ( - 1 ) == 0
if not lazy_autocmds then
2023-01-11 13:00:16 +01:00
M.load ( " autocmds " )
end
2023-01-10 10:44:10 +01:00
2023-10-04 10:45:10 +02:00
local group = vim.api . nvim_create_augroup ( " LazyVim " , { clear = true } )
2023-09-26 10:57:41 +02:00
vim.api . nvim_create_autocmd ( " User " , {
2023-10-04 10:45:10 +02:00
group = group ,
2023-09-26 10:57:41 +02:00
pattern = " VeryLazy " ,
callback = function ( )
if lazy_autocmds then
M.load ( " autocmds " )
end
M.load ( " keymaps " )
perf(core): defer clipboard because xsel and pbcopy can be slow (#4120)
## Description
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
See [this](https://github.com/LazyVim/LazyVim/discussions/4112)
discussion
TLDR:
Startup time performance is affected quite significantly when the
clipboard provider is `xsel`(linux) or `pbcopy`(macos). I expect an
improvement in these cases, especially on older pc's.
This PR resets `vim.opt.clipboard` after the `options` are loaded. Then,
on `VeryLazy`, the setting is restored.
I also tested with `yanky`.
Relevant prints:
1. Before resetting `vim.opt.clipboard` in `init`,
`vim.print(vim.opt.clipboard)` yields a table which will be captured:
```lua
--- fields
_name = "clipboard",
_value = "unnamedplus",
--- more fields
```
2. Set `vim.opt.clipboard = ""` and `vim.print(vim.opt.clipboard)`, also
yields a table:
```lua
--- fields
_name = "clipboard",
_value = "",
--- more fields
```
## Related Issue(s)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
Co-authored-by: abeldekat <abel@nomail.com>
2024-07-20 11:48:11 +02:00
if lazy_clipboard ~= nil then
vim.opt . clipboard = lazy_clipboard
end
2023-10-11 17:48:40 +02:00
2024-03-22 09:15:09 +01:00
LazyVim.format . setup ( )
LazyVim.news . setup ( )
LazyVim.root . setup ( )
2023-10-11 17:48:40 +02:00
vim.api . nvim_create_user_command ( " LazyExtras " , function ( )
2024-03-22 09:15:09 +01:00
LazyVim.extras . show ( )
2023-10-11 17:48:40 +02:00
end , { desc = " Manage LazyVim extras " } )
2024-01-22 08:03:13 +01:00
vim.api . nvim_create_user_command ( " LazyHealth " , function ( )
vim.cmd ( [[Lazy! load all]] )
vim.cmd ( [[checkhealth]] )
end , { desc = " Load all plugins and run :checkhealth " } )
2024-05-19 21:12:51 +02:00
local health = require ( " lazy.health " )
vim.list_extend ( health.valid , {
" recommended " ,
" desc " ,
" vscode " ,
} )
2025-02-08 12:47:41 +01:00
-- Check lazy.nvim import order
local imports = require ( " lazy.core.config " ) . spec.modules
local function find ( pat , last )
for i = last and # imports or 1 , last and 1 or # imports , last and - 1 or 1 do
if imports [ i ] : find ( pat ) then
return i
end
end
end
local lazyvim_plugins = find ( " ^lazyvim%.plugins$ " )
local extras = find ( " ^lazyvim%.plugins%.extras%. " , true ) or lazyvim_plugins
local plugins = find ( " ^plugins$ " ) or math.huge
if lazyvim_plugins ~= 1 or extras > plugins then
vim.notify (
" The order of your `lazy.nvim` imports is incorrect: \n - `lazyvim.plugins` should be first \n - followed by any `lazyvim.plugins.extras` \n - and finally your own `plugins` " ,
" warn " ,
{ title = " LazyVim " }
)
end
2023-09-26 10:57:41 +02:00
end ,
} )
2024-03-22 09:15:09 +01:00
LazyVim.track ( " colorscheme " )
LazyVim.try ( function ( )
2023-01-10 10:44:10 +01:00
if type ( M.colorscheme ) == " function " then
M.colorscheme ( )
else
vim.cmd . colorscheme ( M.colorscheme )
end
end , {
msg = " Could not load your colorscheme " ,
on_error = function ( msg )
2024-03-22 09:15:09 +01:00
LazyVim.error ( msg )
2023-01-10 10:44:10 +01:00
vim.cmd . colorscheme ( " habamax " )
end ,
} )
2024-03-22 09:15:09 +01:00
LazyVim.track ( )
2023-01-10 10:09:52 +01:00
end
2023-10-12 00:09:04 +02:00
---@param buf? number
---@return string[]?
function M . get_kind_filter ( buf )
buf = ( buf == nil or buf == 0 ) and vim.api . nvim_get_current_buf ( ) or buf
local ft = vim.bo [ buf ] . filetype
if M.kind_filter == false then
return
end
2023-10-15 22:34:42 +02:00
if M.kind_filter [ ft ] == false then
return
end
2024-03-27 15:04:22 +01:00
if type ( M.kind_filter [ ft ] ) == " table " then
return M.kind_filter [ ft ]
end
2023-10-15 22:34:42 +02:00
---@diagnostic disable-next-line: return-type-mismatch
return type ( M.kind_filter ) == " table " and type ( M.kind_filter . default ) == " table " and M.kind_filter . default or nil
2023-10-12 00:09:04 +02:00
end
2023-01-10 10:20:28 +01:00
---@param name "autocmds" | "options" | "keymaps"
function M . load ( name )
2023-02-11 08:59:42 +01:00
local function _load ( mod )
2023-10-10 19:29:24 +02:00
if require ( " lazy.core.cache " ) . find ( mod ) [ 1 ] then
2024-03-22 09:15:09 +01:00
LazyVim.try ( function ( )
2023-10-10 19:29:24 +02:00
require ( mod )
end , { msg = " Failed loading " .. mod } )
end
2023-01-10 10:20:28 +01:00
end
2024-07-08 07:52:18 +02:00
local pattern = " LazyVim " .. name : sub ( 1 , 1 ) : upper ( ) .. name : sub ( 2 )
2023-02-11 08:59:42 +01:00
-- always load lazyvim, then user file
2023-04-16 11:34:35 +02:00
if M.defaults [ name ] or name == " options " then
2023-02-11 08:59:42 +01:00
_load ( " lazyvim.config. " .. name )
2024-07-08 07:52:18 +02:00
vim.api . nvim_exec_autocmds ( " User " , { pattern = pattern .. " Defaults " , modeline = false } )
2023-02-11 08:59:42 +01:00
end
_load ( " config. " .. name )
2023-01-11 12:56:07 +01:00
if vim.bo . filetype == " lazy " then
-- HACK: LazyVim may have overwritten options of the Lazy ui, so reset this here
vim.cmd ( [[do VimResized]] )
end
2023-05-24 08:45:20 +02:00
vim.api . nvim_exec_autocmds ( " User " , { pattern = pattern , modeline = false } )
2023-01-10 10:20:28 +01:00
end
2023-01-10 23:00:56 +01:00
M.did_init = false
function M . init ( )
2023-10-10 21:51:09 +02:00
if M.did_init then
return
end
M.did_init = true
local plugin = require ( " lazy.core.config " ) . spec.plugins . LazyVim
if plugin then
vim.opt . rtp : append ( plugin.dir )
end
2023-10-10 19:29:24 +02:00
2023-10-10 21:51:09 +02:00
package.preload [ " lazyvim.plugins.lsp.format " ] = function ( )
2024-03-22 09:15:09 +01:00
LazyVim.deprecate ( [[require("lazyvim.plugins.lsp.format")]] , [[LazyVim.format]] )
return LazyVim.format
2023-10-10 21:51:09 +02:00
end
2023-10-06 18:35:17 +02:00
2023-10-10 21:51:09 +02:00
-- delay notifications till vim.notify was replaced or after 500ms
2024-03-22 09:15:09 +01:00
LazyVim.lazy_notify ( )
2023-01-10 23:00:56 +01:00
2023-10-10 21:51:09 +02:00
-- load options here, before lazy init while sourcing plugin modules
-- this is needed to make sure options will be correctly applied
-- after installing missing plugins
M.load ( " options " )
perf(core): defer clipboard because xsel and pbcopy can be slow (#4120)
## Description
<!-- Describe the big picture of your changes to communicate to the
maintainers
why we should accept this pull request. -->
See [this](https://github.com/LazyVim/LazyVim/discussions/4112)
discussion
TLDR:
Startup time performance is affected quite significantly when the
clipboard provider is `xsel`(linux) or `pbcopy`(macos). I expect an
improvement in these cases, especially on older pc's.
This PR resets `vim.opt.clipboard` after the `options` are loaded. Then,
on `VeryLazy`, the setting is restored.
I also tested with `yanky`.
Relevant prints:
1. Before resetting `vim.opt.clipboard` in `init`,
`vim.print(vim.opt.clipboard)` yields a table which will be captured:
```lua
--- fields
_name = "clipboard",
_value = "unnamedplus",
--- more fields
```
2. Set `vim.opt.clipboard = ""` and `vim.print(vim.opt.clipboard)`, also
yields a table:
```lua
--- fields
_name = "clipboard",
_value = "",
--- more fields
```
## Related Issue(s)
<!--
If this PR fixes any issues, please link to the issue here.
- Fixes #<issue_number>
-->
## Screenshots
<!-- Add screenshots of the changes if applicable. -->
## Checklist
- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
Co-authored-by: abeldekat <abel@nomail.com>
2024-07-20 11:48:11 +02:00
-- defer built-in clipboard handling: "xsel" and "pbcopy" can be slow
lazy_clipboard = vim.opt . clipboard
vim.opt . clipboard = " "
2023-10-04 10:45:10 +02:00
2024-05-17 09:19:22 +02:00
if vim.g . deprecation_warnings == false then
vim.deprecate = function ( ) end
end
2024-03-22 09:15:09 +01:00
LazyVim.plugin . setup ( )
2023-10-11 17:47:16 +02:00
M.json . load ( )
2023-01-10 23:00:56 +01:00
end
2025-02-08 15:04:46 +01:00
---@alias LazyVimDefault {name: string, extra: string, enabled?: boolean, origin?: "global" | "default" | "extra" }
local default_extras ---@type table<string, LazyVimDefault>
function M . get_defaults ( )
if default_extras then
return default_extras
end
---@type table<string, LazyVimDefault[]>
local checks = {
picker = {
{ name = " snacks " , extra = " editor.snacks_picker " } ,
2025-02-08 15:23:30 +01:00
{ name = " fzf " , extra = " editor.fzf " } ,
2025-02-08 15:04:46 +01:00
{ name = " telescope " , extra = " editor.telescope " } ,
} ,
cmp = {
{ name = " blink.cmp " , extra = " coding.blink " , enabled = vim.fn . has ( " nvim-0.10 " ) == 1 } ,
{ name = " nvim-cmp " , extra = " coding.nvim-cmp " } ,
} ,
explorer = {
{ name = " snacks " , extra = " editor.snacks_explorer " } ,
2025-02-08 15:23:30 +01:00
{ name = " neo-tree " , extra = " editor.neo-tree " } ,
2025-02-08 15:04:46 +01:00
} ,
}
2025-02-08 15:23:30 +01:00
-- existing installs keep their defaults
if ( LazyVim.config . json.data . install_version or 7 ) < 8 then
table.insert ( checks.picker , 1 , table.remove ( checks.picker , 2 ) )
table.insert ( checks.explorer , 1 , table.remove ( checks.explorer , 2 ) )
end
2025-02-08 15:04:46 +01:00
default_extras = { }
for name , check in pairs ( checks ) do
local valid = { } ---@type string[]
for _ , extra in ipairs ( check ) do
if extra.enabled ~= false then
valid [ # valid + 1 ] = extra.name
end
end
local origin = " default "
local use = vim.g [ " lazyvim_ " .. name ]
use = vim.tbl_contains ( valid , use or " auto " ) and use or nil
origin = use and " global " or origin
for _ , extra in ipairs ( use and { } or check ) do
if extra.enabled ~= false and LazyVim.has_extra ( extra.extra ) then
use = extra.name
break
end
end
origin = use and " extra " or origin
use = use or valid [ 1 ]
for _ , extra in ipairs ( check ) do
local import = " lazyvim.plugins.extras. " .. extra.extra
extra = vim.deepcopy ( extra )
extra.enabled = extra.name == use
if extra.enabled then
extra.origin = origin
end
default_extras [ import ] = extra
end
end
return default_extras
end
2023-01-10 10:07:19 +01:00
setmetatable ( M , {
__index = function ( _ , key )
if options == nil then
2023-01-25 08:56:48 +01:00
return vim.deepcopy ( defaults ) [ key ]
2023-01-10 10:07:19 +01:00
end
---@cast options LazyVimConfig
return options [ key ]
end ,
} )
return M