This is a list of examples of how to lazyload plugins.
The examples use packer as their plugin manager.
Table of contents
- simple lazyloading examples
- complex lazyloading examples
- requires lazyloading examples
- rplugin lazyloading examples
- builtin lazyloading examples
simple lazyloading examples
use{'nvim-telescope/telescope.nvim',cmd='Telescope'}
use{'tommcdo/vim-lion',keys={{'x','gl'},{'n','gl'},{'x','gL'},{'n','gL'}}}
complex lazyloading examples
use{'hrsh7th/nvim-cmp',requires={
{'hrsh7th/cmp-buffer',after='nvim-cmp'}
}}
use{'glepnir/dashboard-nvim',
cmd={'Dashboard','DashboardNewFile'},
setup=function ()
vim.api.nvim_create_autocmd('Vimenter',{callback=function()
if vim.fn.argc()==0 and vim.fn.line2byte('$')==-1 then
vim.cmd'Dashboard'
end
end})
end
}
use{'anuvyklack/pretty-fold.nvim',
requires='anuvyklack/nvim-keymap-amend',
config='require "pretty-fold".setup{}',
event='User isfolded',
setup=function ()
local fn=vim.fn
local fastfoldtimer
fastfoldtimer=fn.timer_start(2000,function()
if #fn.filter(fn.range(1,fn.line'$'),'foldlevel(v:val)>0')>0 then
vim.cmd('doautocmd User isfolded')
fn.timer_stop(fastfoldtimer)
end
end,{['repeat']=-1})
end
}
use{'elihunter173/dirbuf.nvim',
cmd={'Dirbuf'},
setup=function()
vim.api.nvim_create_autocmd('BufEnter',{
command="if isdirectory(expand('%')) && !&modified|execute 'Dirbuf'|endif"
})
end
}
requires lazyloading examples
use{'rbong/vim-flog',
setup=function ()
vim.api.nvim_create_user_command(cmd,[[
lua require"packer.load"({"vim-fugitive"},{},_G.packer_plugins)
require"packer.load"({"vim-flog"},{cmd="Flog",l1=<line1>,l2=<line2>,bang=<q-bang>,args=<q-args>,mods="<mods>"},_G.packer_plugins)]],
{nargs='*',range=true,bang=true,complete='file'}
)
end,
opt=true
}
use{'tpope/vim-fugitive',
opt=true
}
rplugin lazyloading examples
vim.g.loaded_remote_plugins="not loaded"
use{'ripxorip/aerojump.nvim',
config=function ()
vim.cmd[[
if g:loaded_remote_plugins=="not loaded"
unlet g:loaded_remote_plugins
source /usr/share/nvim/runtime/plugin/rplugin.vim
endif
]]
end,
cmd='Aerojump'
}
builtin lazyloading examples
vim.g.loaded_tutor_mode_plugin=1
vim.api.nvim_create_user_command('Tutor',[[
delcommand Tutor
unlet g:loaded_tutor_mode_plugin
source /usr/share/nvim/runtime/plugin/tutor.vim
Tutor <args>]],{nargs='?',complete='custom,tutor#TutorCmdComplete'})