lazy.nvim
lazy.nvim copied to clipboard
Vimscript plugin not loading when key is activated
Describe the bug
I am trying testing out this plugin. Everything seems to be going fine, except when lazy loading some vim plugins.
This is how things are setup in packer
.
use {
'zirrostig/vim-schlepp',
keys = {'<Plug>SchleppUp', '<Plug>SchleppDown'},
}
Kepmapping defined in some other file:
map ("v", [[<s-up>]], [[<Plug>SchleppUp]], {noremap = false})
map ("v", [[<s-down>]], [[<Plug>SchleppDown]], {noremap = false})
I tried this with lazy
, but it is not loaded when I press the trigger keys.
{
'zirrostig/vim-schlepp',
keys = {'<plug>SchleppUp', '<plug>SchleppDown'},
},
Which version of Neovim are you using? v0.8.1
The keys should be <s-up>
and <s-down>
probably? You're setting the rhs
, but it should be the lhs
?
You also use <plug>
instead of <Plug>
, so maybe that's the issue?
I tried using <s-up>
and <plug>
. The plugin doesn't load.
Looking at some of the recently closed issues, I tried the following:
{
'zirrostig/vim-schlepp',
keys = {
{'<plug>SchleppUp', mode = "v"},
{'<s-down>', mode = "v"},
},
},
Pressing <s-down>
doesn't do anything. However, pressing <s-up>
, which is mapped to <plug>SchleppUp
gives the following error.
E5108: Error executing lua: ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:103: attempt to index local 'plugins' (a nil value)
stack traceback:
...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:103: in function 'load'
...share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/keys.lua:51: in function <...share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/keys.lua:48>
Failed to source `/home/medwatt/.local/share/nvim/lazy/vim-schlepp/plugin/schlepp.vim`
...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:189: Vim(noremap):E227: mapping already exists for <80><fd>SSchleppUp
Can you provide a minimal init.lua? And add in the keys that worked with packer.
Here's a minimal config for packer
.
local install_path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.api.nvim_command('packadd packer.nvim')
end
local packer = require('packer')
local use = require('packer').use
local plugins = function()
-- Packer
use {'wbthomason/packer.nvim'}
-- Firenvim
use {
'zirrostig/vim-schlepp',
keys = {'<Plug>SchleppUp', '<Plug>SchleppDown'}
}
end
packer.startup(plugins)
local map = vim.keymap.set
map ("v", [[<s-up>]], [[<Plug>SchleppUp]], {noremap = false})
map ("v", [[<s-down>]], [[<Plug>SchleppDown]], {noremap = false})
Here's for lazy
:
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",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
require("lazy").setup {
{
'zirrostig/vim-schlepp',
keys = {'<plug>SchleppUp', '<Plug>SchleppDown'},
},
}
local map = vim.keymap.set
map ("v", [[<s-up>]], [[<Plug>SchleppUp]], {noremap = false})
map ("v", [[<s-down>]], [[<Plug>SchleppDown]], {noremap = false})
I see this issue has been closed. I just updated to the latest version of lazy. The plugin is still not loading.
Sorry, forgot to mention that you need to fix your mapping:
{
"zirrostig/vim-schlepp",
keys = { { "<Plug>SchleppUp", mode = "v" }, { "<Plug>SchleppDown", mode = "v" } },
},
Thanks for the fix, but it still doesn't work. Holding shift and up (as defined by the keybinding) works once and then stops.
Here's a video.
https://user-images.githubusercontent.com/17733465/209195867-9ddfff8f-4b34-4b96-b7e7-58b5758a59e7.mp4
Just pushed another fix. Can you verify?
Issue fixed, thanks!!!! Sorry for taking too much of your time.
@folke, I updated today lazy
today and I started experiencing the behavior I reported here.
This might also be related. I use the plugin called vim-sandwich and I have the keymapping below to replace a pair of parenthesis, brackets, etc.
map ("n", [[gsr]], [[<plug>(operator-sandwich-replace)<plug>(textobj-sandwich-query-a)]], {noremap = false})
map ("n", [[gsrr]], [[<plug>(operator-sandwich-replace)<plug>(textobj-sandwich-auto-a)]], {noremap = false})
This is how I call the plugin.
{
'machakann/vim-sandwich',
keys = {
{ "<plug>(operator-sandwich-replace)", mode = "n" },
},
config = function() require('main.plugin.sandwich') end
},
When I press gsrr
, the plugin loads, but the action is not executed. Pressing gsrr
a second time works. The correct behavior is that the plugin should load and the action should be executed.
I tried doing this, but it got an error when loading vim.
{
'machakann/vim-sandwich',
keys = {
{ "<plug>(operator-sandwich-replace)<plug>(textobj-sandwich-query-a)", mode = "n" },
},
config = function() require('main.plugin.sandwich') end
},
Just checked that vimtex also doesn't seem to work. The plugin is supposed to load inside .tex
files.
{
'lervag/vimtex',
ft = { 'tex' },
config = function() vim.cmd('source ' .. path .. 'vimtex.vim') end
},
Inside a .tex
file, running execute "normal \<plug>(vimtex-status)"
is supposed to display something. However, lazy loading the plugin as shown above results in nothing being displayed.
Do not load filetype plugins (like vimtex) on FileType
events -- this will not work, since the plugins need to set things up before the filetype is set.
Just set lazy=false
; VimTeX itself is sufficiently "lazy".
@clason,
- with
packer
, I was lazy loading it the same way and it worked fine. Not lazy loading it takes about 1ms on my machine. Not a lot of time, but since I am not always editing latex files, seems a bit wasteful to be loading it every time vim starts. - what about filetype plugins that are not sufficiently "lazy", what do you do about them?
with packer, I was lazy loading it the same way and it worked fine. Not lazy loading it takes about 1ms on my machine. Not a lot of time, but since I am not always editing latex files, seems a bit wasteful to be loading it every time vim starts.
Sorry, that can't be -- this is a known and documented fact that loading VimTeX on a FileType
event does not work. Either the loading was subtly different, or it also didn't work and you just didn't notice.
what about filetype plugins that are not sufficiently "lazy", what do you do about them?
Report it to the plugin author so they can fix it.
As I am just a user, I assumed that packer was indeed not loading the plugin. Here's a video showing that. Is packer faking it (that the plugin is not loaded) ?
https://user-images.githubusercontent.com/17733465/209438057-f725474b-45a0-4aed-97ed-3a5f012a21f6.mp4
I will check if this is lazy, but @clason is probably right.
What lazy does when lazy-loading on a filetype:
- we make a list of all the
augroups
that are listening to filetype events - we load the plugin (inccluding
/pugin
and/ftdetect
) - we check if any new augroups/autocmds have been created by the plugin
- we trigger the filetype event for the new groups
But since there is a specific message in vimtext docs about lazy-loading, there's probably a very specific reason why this does not work there.
The plugins I'm using ft
for, work as expected.
Thanks for the update. Can you tell whether packer is actually loading the plugin even when it says "not loaded"?
I can confirm that the original issue is back. Will look into it further tomorrow.
@medwatt I can't tell you anthing about packer. no idea
Just checked that vimtex also doesn't seem to work. The plugin is supposed to load inside
.tex
files.
I confirm that vimtex
does work if you remove ft = { 'tex' }
(I stumbled across the same problem some time ago).
It should obviously work when you remove that line since it is no longer lazy-loaded.
If I can add something to the conversation, the ft table now works for the vimtex plugin for me. Not sure if anything changed.
Config
{
"lervag/vimtex",
ft = { "tex" },
config = function()
return {
["vimtex_view_general_viewer"] = "SumatraPDF",
["vimtex_view_method"] = "SumatraPDF",
["vimtex_view_general_options"] = "-reuse-instance -forward-search @tex @line @pdf",
["vimtex_view_general_options_latexmk"] = "-reuse-instance",
}
end,
},
When opening my init.lua file.
When opening my .tex file
I really hope everyone gets it to work for them. Lazy loading is sick and I think this project is awesome! ❤️
When opening my .tex file
are you able to operate on the .tex
file with vimtex though, in this case? If I do so too (namely if I do specify ft=tex
), many of the vimtex commands and options do not work.
About the original issue with the keys, I suspect this to be a Neovim issue, but might be a feature, I don't know
vim.keymap.set("n", "<Plug>Foobar", error)
vim.keymap.set("n", "F", "<Plug>Foobar")
vim.keymap.del("n", "<Plug>Foobar")
vim.keymap.del("n", "<Plug>Foobar")
The code above correctly gives an error on line 4 that the keymap does not exist.
vim.keymap.set("n", "<Plug>Foobar", error)
vim.keymap.set("n", "<c-f>", "<Plug>Foobar")
vim.keymap.del("n", "<Plug>Foobar")
vim.keymap.del("n", "<Plug>Foobar")
Same code, but now I use <c-f>
instead of F
. No error and keymaps on line 1 and 2 are deleted
Which doesn't seem right?
I've posted an issue at Neovim's repo https://github.com/neovim/neovim/issues/21530
I was able to fix this, by making sure we only delete the lazy key mapping once
I would like to understand what the "Plug" directive (in brackets) does. Can anyone point me where I can find the documentation for that?
@gennaro-tedesco make sure ft is a table of strings which signify filetypes. Try that and lemme know if that doesn't work.
make sure ft is a table of strings
As per the examples in the README, ft = ...
needs not be a table necessarily, a string is fine too (or am i wrong?). This said, probably we should move this discussion elsewhere to avoid polluting this issue which is now closed and solved :)
@GersiD :h <Plug>