unblevable / quick-scope

Lightning fast left-right movement in Vim
MIT License
1.42k stars 54 forks source link

Undefined variable s:chars_s #98

Closed w2kpro closed 2 months ago

w2kpro commented 7 months ago

Vim 9.1 on Manjaro Linux (vim -f -u .vimrc-core) quick-scope installed using Plug Added "let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']" to .vimrc-core Characters are highlighted, but when cursor is moved to a new line the following error occurs: Error detected while processing function quick_scope#HighlightLineDelayCallback[2]..quick_scope

HighlightLine[12]..49_get_highlight_patterns[130]..49_save_chars_with_secondary_high

lights: line 6: E121: Undefined variable: s:chars_s

vizcay commented 6 months ago

Exact same problem here with NVIM v0.9.4 and

  vim.cmd [[
    let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
    augroup qs_colors
      autocmd!
      autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline
      autocmd ColorScheme * highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline
    augroup END
  ]]
Screenshot 2024-02-25 at 16 58 23
ktowen commented 3 months ago

Any solution for this?

quolpr commented 3 months ago

Issue still present. Issue happens when qs_highlight_on_keys is set

unblevable commented 2 months ago

I can't reproduce the error while running NVIM v0.9.4 on Ubuntu 22.04. Can someone provide more context, possibly their .vimrc?

ktowen commented 2 months ago

I'm able to reproduce it with this configuration. It only fails at the beginning of the lines at the end of the config

-- Install `lazy.nvim` plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    local lazyrepo = "https://github.com/folke/lazy.nvim.git"
    vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "unblevable/quick-scope",
        config = function()
            vim.g.qs_highlight_on_keys = { "f", "F", "t", "T" }
        end,
    },
})

-- NVIM v0.10.0
--------------------------------------
--- Next lines will give an error
--------------------------------------

--
-- export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
--
-- # zstyle ':omz:update' mode disabled  # disable automatic updates
--
bradford-smith94 commented 2 months ago

Thanks @ktowen, using this config I can reproduce (nvim v0.10.0 on Archlinux).

Interesting findings:

I'm still trying to dig into the why a bit more, but from this I can already tell that g:qs_highlight_on_keys (although it is being set) is not being set before quick-scope is initialized, which is something the plugin does not currently support.

This error has something to do with when folke/lazy.nvim is actually setting the variable. I haven't checked out that plugin yet, but I've confirmed this by moving the variable set line to outside of that lazy plugin and the error has disappeared (as well as quick-scope actually runs in g:qs_highlight_on_keys mode) -- i.e. - the following config does not cause the error:

-- Install `lazy.nvim` plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    local lazyrepo = "https://github.com/folke/lazy.nvim.git"
    vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)

vim.g.qs_highlight_on_keys = { "f", "F", "t", "T" }
require("lazy").setup({
    {
        "unblevable/quick-scope",
        config = function()
            vim.g.qs_highlight_on_keys = { "f", "F", "t", "T" }
        end,
    },
})

-- NVIM v0.10.0
--------------------------------------
--- Next lines will give an error
--------------------------------------

--
-- export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
--
-- # zstyle ':omz:update' mode disabled  # disable automatic updates
--
bradford-smith94 commented 2 months ago

Removed the "plugin-interactions" label, while the specific config I tested was caused by another plugin interaction this issue is more generally a timing issue caused by when g:qs_highlight_on_keys is set.

The latest update v2.6.2 should avoid the errors by locking in the operating mode at plugin initialization. But there still exists a potential for miss-config where the user thinks they have set g:qs_highlight_on_keys (as above) but because of when the plugin is actually initialized vs when the variable is actually set quick-scope may not behave in "keys" highlighting mode.

bradford-smith94 commented 2 months ago

Added a note to README, also see #72.

Closing this issue, as it is now linked in README so finding the relevant discussion should be possible.

josh-nz commented 2 months ago

You want to use the init function in the Lazy plugin manager spec for this plugin:

return {
  "unblevable/quick-scope",
  init = function()
    vim.g.qs_highlight_on_keys = { "f", "F", "t", "T" }
  end,
}

Ref: https://lazy.folke.io/spec