feat(root): disable expensive plugins during paste to avoid lag
Prevents performance degradation when using paste with configured plugins.
This commit is contained in:
2 files changed
+50
-8
No files matched your search
@@ -5,4 +5,46 @@ require('options')
|
||||
require('autocmd')
|
||||
require('lsp')
|
||||
|
||||
-- Disable expensive features during paste to avoid lag
|
||||
do
|
||||
local function disable(buf)
|
||||
vim.b[buf]._paste_state = { lsp = vim.diagnostic.is_enabled(), mini = vim.b[buf].miniindentscope_disable }
|
||||
if vim.b[buf]._paste_state.lsp then vim.diagnostic.enable(false) end
|
||||
vim.b[buf].miniindentscope_disable = true
|
||||
vim.b[buf].ts_highlight_disable = true
|
||||
vim.b[buf].ts_indent_disable = true
|
||||
end
|
||||
|
||||
local function enable(buf)
|
||||
local s = vim.b[buf]._paste_state
|
||||
if s then
|
||||
if s.lsp then vim.diagnostic.enable() end
|
||||
vim.b[buf].miniindentscope_disable = s.mini
|
||||
end
|
||||
vim.b[buf]._paste_state = nil
|
||||
vim.b[buf].ts_highlight_disable = nil
|
||||
vim.b[buf].ts_indent_disable = nil
|
||||
end
|
||||
|
||||
local orig_paste = vim.paste
|
||||
vim.paste = function(lines, phase)
|
||||
if phase == 'start' then disable(vim.api.nvim_get_current_buf())
|
||||
elseif phase == 'finish' then vim.schedule(function() enable(vim.api.nvim_get_current_buf()) end) end
|
||||
return orig_paste(lines, phase)
|
||||
end
|
||||
|
||||
local function perf_paste(cmd)
|
||||
return function()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
disable(buf)
|
||||
local reg = vim.v.register
|
||||
vim.cmd('normal! "' .. reg .. cmd)
|
||||
vim.schedule(function() enable(buf) end)
|
||||
end
|
||||
end
|
||||
|
||||
vim.keymap.set('n', 'p', perf_paste('p=`]'), { desc = 'Paste and auto-indent' })
|
||||
vim.keymap.set('n', 'P', perf_paste('P=`]'), { desc = 'Paste before and auto-indent' })
|
||||
end
|
||||
|
||||
|
||||
+8
-8
@@ -9,11 +9,11 @@
|
||||
"src": "https://github.com/serhez/bento.nvim"
|
||||
},
|
||||
"blink.cmp": {
|
||||
"rev": "39682a9c737920578cf68887c21eaa4ce3845c67",
|
||||
"rev": "bda905a4bf1b3edfa708b0be193b8c63d8620c96",
|
||||
"src": "https://github.com/saghen/blink.cmp"
|
||||
},
|
||||
"blink.lib": {
|
||||
"rev": "08ac9a9b873d3c7376e408a36c40c4131e2809ce",
|
||||
"rev": "5876dd95deeb70aadbe9f1c0b7117a135061cdac",
|
||||
"src": "https://github.com/saghen/blink.lib"
|
||||
},
|
||||
"conform.nvim": {
|
||||
@@ -29,7 +29,7 @@
|
||||
"src": "https://github.com/wintermute-cell/gitignore.nvim"
|
||||
},
|
||||
"gitsigns.nvim": {
|
||||
"rev": "25050e4ed39e628282831d4cbecb1850454ce915",
|
||||
"rev": "2038c666bd9d8a0b7349a0b6ee00dc83104b9ecf",
|
||||
"src": "https://github.com/lewis6991/gitsigns.nvim"
|
||||
},
|
||||
"gruvbox.nvim": {
|
||||
@@ -49,7 +49,7 @@
|
||||
"src": "https://github.com/iamcco/markdown-preview.nvim"
|
||||
},
|
||||
"markview.nvim": {
|
||||
"rev": "576e50fa99091ff47a9920e1b6ef94b2a7c2f036",
|
||||
"rev": "301e431c7b618235f5447d54465c70934bd33668",
|
||||
"src": "https://github.com/OXY2DEV/markview.nvim"
|
||||
},
|
||||
"mason-conform.nvim": {
|
||||
@@ -57,7 +57,7 @@
|
||||
"src": "https://github.com/zapling/mason-conform.nvim"
|
||||
},
|
||||
"mason-lspconfig.nvim": {
|
||||
"rev": "21c5b3ebeaa0412e28096bb0701434c51c1fbf76",
|
||||
"rev": "47059d71b42d74b0a1e9f61c1d99d301039c3b5b",
|
||||
"src": "https://github.com/mason-org/mason-lspconfig.nvim"
|
||||
},
|
||||
"mason-nvim-lint": {
|
||||
@@ -73,7 +73,7 @@
|
||||
"src": "https://github.com/davidmh/mdx.nvim"
|
||||
},
|
||||
"mini.nvim": {
|
||||
"rev": "bf8169f3e518be8de3f88073ace37d91f576cb04",
|
||||
"rev": "1599a473aa6f5290a5d740b1144846e6f0c3963d",
|
||||
"src": "https://github.com/echasnovski/mini.nvim"
|
||||
},
|
||||
"nvim-highlight-colors": {
|
||||
@@ -81,11 +81,11 @@
|
||||
"src": "https://github.com/brenoprata10/nvim-highlight-colors"
|
||||
},
|
||||
"nvim-lint": {
|
||||
"rev": "99cbc3ca8a76845fca50e496be7212bebf907dd3",
|
||||
"rev": "a219b2c9e5b4765e5c845aba119dad55806fcaf1",
|
||||
"src": "https://github.com/mfussenegger/nvim-lint"
|
||||
},
|
||||
"nvim-lspconfig": {
|
||||
"rev": "a683e0ddf0cf64c6cd689e18ffb480ade3c162b7",
|
||||
"rev": "3371bf298c1f56efc26771ee961f461176958fb5",
|
||||
"src": "https://github.com/neovim/nvim-lspconfig"
|
||||
},
|
||||
"nvim-treesitter": {
|
||||
|
||||
Reference in new issue
Block a user