ggandor / lightspeed.nvim

deprecated in favor of leap.nvim
MIT License
1.56k stars 28 forks source link

Problems when setting safe_labels = {} #155

Closed yyy33 closed 2 years ago

yyy33 commented 2 years ago

This is my config file

require'lightspeed'.setup {
    exit_after_idle_msecs = { labeled = nil, unlabeled = 0 },

    jump_to_unique_chars = { safety_timeout = 0 },

    match_only_the_start_of_same_char_seqs = true,

    safe_labels = {},

    limit_ft_matches = 0
}

vim.g.lightspeed_no_default_keymaps = 1

vim.keymap.set({'n', 'x'}, 's',  '<Plug>Lightspeed_s',   {silent = true})
vim.keymap.set({'n', 'x'}, 'S',  '<Plug>Lightspeed_S',   {silent = true})
vim.keymap.set({'n', 'x'}, 'gs', ' <Plug>Lightspeed_gs', {silent = true})
vim.keymap.set({'n', 'x'}, 'gS', ' <Plug>Lightspeed_gS', {silent = true})
vim.keymap.set({'n', 'x'}, 'f',  '<Plug>Lightspeed_f',   {silent = true})
vim.keymap.set({'n', 'x'}, 'F',  '<Plug>Lightspeed_F',   {silent = true})
vim.keymap.set({'n', 'x'}, 't',  '<Plug>Lightspeed_t',   {silent = true})
vim.keymap.set({'n', 'x'}, 'T',  '<Plug>Lightspeed_T',   {silent = true})

vim.g.lightspeed_last_motion = ''
vim.cmd [[
    augroup lightspeed_last_motion
        autocmd!
        autocmd User LightspeedSxEnter let g:lightspeed_last_motion = 'sx'
        autocmd User LightspeedFtEnter let g:lightspeed_last_motion = 'ft'
    augroup end
]]
vim.keymap.set({'n', 'x'}, ';',  [[g:lightspeed_last_motion == 'sx' ? "<Plug>Lightspeed_;_sx" : "<Plug>Lightspeed_;_ft"]],   {expr = true})
vim.keymap.set({'n', 'x'}, ',',  [[g:lightspeed_last_motion == 'sx' ? "<Plug>Lightspeed_,_sx" : "<Plug>Lightspeed_,_ft"]],   {expr = true})

This is test text

package main

import (
    "os"
    help "translateHelpDoc/help/vim"
    "translateHelpDoc/log"

    "github.com/alecthomas/kong"
)

func main() {
    log.SetLevel(log.DebugLevel)
    f, _ := os.Create("aa")
    log.SetOutput(f)
    ctx := kong.Parse(&CLI{})
    err := ctx.Run()
    log.FatalWithCheck(err)
}

type CLI struct {
    Data  string   `flag:"" required:"" short:"d" help:"Directory for saving translation results"`
  1. My cursor at the beginning of the file with 2022-07-14_12-27

  2. When I type sogf, my cursor is at line 12 2022-07-14_12-28

  3. I type ; multiple times, the cursor is at the last og in the screen, which is line 17 2022-07-14_12-28_1

  4. After I typed , multiple times, the cursor finally came to the 12th line and couldn't go back, normally it should go back to the og of the 6th line 2022-07-14_12-29

5.When I don't set the safe_labels = {} option, everything works fine

ggandor commented 2 years ago

There is no bug here: ,/; do not behave like , and ; in vanilla Vim. You can only go back to the "start point" (the first target you reached with ;), but not beyond - it is like pushing and popping from a stack.

The reason why it works like this is briefly mentioned in the Readme (;/, works the same way as S/F/T):

S, F and T, on the other hand, always revert the previous repeat. Note that in the case of T (or X, if mapped), this results in a different, and presumably more useful behaviour than what you are used to in clever-f and Sneak: it does not repeat the search in the reverse direction, but puts the cursor back to its previous position - before the previous match -, allowing for an easy correction when you accidentally overshoot your target.

What this means in practice, regarding your example:

If you have safe labels, you will auto-jump to the first target, and that will be the start point for ;/,. If you set safe_labels = {}, you will not auto-jump, so if you press a label, then you actually exit the plugin. If you jumped to the second match (by selecting the label f), then the match after that will be the first one that ; finds (the one in log.DebugLevel on line 12), and thus the "reference" point for the ;/, sequence.