liuchengxu / vim-which-key

:tulip: Vim plugin that shows keybindings in popup
https://liuchengxu.github.io/vim-which-key/
MIT License
1.93k stars 65 forks source link

In visual mode, which key seems to make cursor jump before command actually executed #241

Open zhyzky opened 1 year ago

zhyzky commented 1 year ago

Warning: if you don't fill this issue template and provide the reproducible steps the issue could be closed directly.

Environment (please complete the following information):

Describe the bug When in visual mode, after which-key hint pops, and just before the actual command executed. You may notice that the cursor jumps at the beginning of line.

To Reproduce Steps to reproduce the behavior:

  1. Create a vimrc

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

zhyzky commented 1 year ago

This issue not happens on windows. the config file:

nnoremap xnoremap let g:mapleader = " " let g:maplocalleader = ',' nnoremap :WhichKey '' nnoremap :WhichKey ',' vnoremap :WhichKeyVisual '' call which_key#register('', "g:which_key_map") let g:which_key_map={}

nmap aa MarkSet xmap aa MarkSet nmap ar MarkRegex xmap ar MarkRegex nmap ad MarkClear nmap ac :nohMarkAllClear xmap ac :nohMarkAllClear nmap as MarkSearchAnyNext nmap aS MarkSearchAnyPrev nmap an MarkSearchCurrentNext nmap aN MarkSearchCurrentPrev

let g:which_key_map['a']={ \ 'name': '+Mark', \ 'a': 'Mark current', \ 'r': 'Mark regex', \ 'd': 'Mark remove', \ 'c': 'Clear all mark', \ 's': 'Next mark', \ 'S': 'Prev mark', \ 'n': 'CurrentMark Next', \ 'N': 'CurrentMark Prev', \ }

zhyzky commented 1 year ago

After some investigation, the issue seems related to: autoload/which_key.vim, line 403, where a line number add before the Cmd. Not Sure What's going on with the line range here

tkapias commented 11 months ago

I confirm the same issue, it's impossible to use a selected range.

I did not use VWK on the selection before but I would like to sort a spaced list inside a range on the same line.

vnoremap <F2> d:execute 'normal a' . join(uniq(sort(split(getreg('"')))), ' ')<CR>
let g:which_key_map_visual.n.s    = 'sort+uniq(spacedWords)'
vnoremap <Leader>ns d:execute 'normal a' . join(uniq(sort(split(getreg('"')))), ' ')<CR>
zhyzky commented 11 months ago

I confirm the same issue, it's impossible to use a selected range.

I did not use VWK on the selection before but I would like to sort a spaced list inside a range on the same line.

  • Without VWK the command affect the current selection in visual mode and it works:
vnoremap <F2> d:execute 'normal a' . join(uniq(sort(split(getreg('"')))), ' ')<CR>
  • But with VWK, pressing the leader key exits the selection and affect only the cursor location. It would work if it affected the last selection, but I don't know how. Should I put '<,'> somewhere?
let g:which_key_map_visual.n.s    = 'sort+uniq(spacedWords)'
vnoremap <Leader>ns d:execute 'normal a' . join(uniq(sort(split(getreg('"')))), ' ')<CR>

Maybe you can just comment out the line " let Cmd = line('v').','.line('.').Cmd " Didn't get the purpose of line range here, there might be some side effect, though I havn't met yet.