markonm / traces.vim

Range, pattern and substitute preview for Vim
MIT License
742 stars 13 forks source link

In visual mode, `:` command input moves the cursor to the end of the selected range #48

Closed KSR-Yasuda closed 5 months ago

KSR-Yasuda commented 5 months ago

With this plugin, pushing : in visual selected, the cursor moves the end of the range.

:new
:0r !seq 1 20       " Put the line number to each line.

:setl nu rnu        " Set `releativenumber`

:10
Shift-V
4j                  " Visual select L10 - 14 (cursor is at L14).
o                   " Move the cursor to the head of the range, L10.

:                   " Begin to input command,
                    " and it moves the cursor to the end of the range, L14, unexpectedly.

vim_rnu_range_20240607_104635

With relativenumber option, this is harmful: commands works as the cursor is at the head of the range ('<), but displayed relativenumbers are not the relative ones from the line.

Could you take a look into this?

cf. https://github.com/vim-jp/issues/issues/1432

KSR-Yasuda commented 5 months ago

The cursor() looks moving the cursor pos to the range end '>.

--- a/autoload/traces.vim
+++ b/autoload/traces.vim
@@ -582,7 +582,6 @@ function! s:pos_range(end, pattern) abort
     endif
     unlet s:buf[s:nr].pre_cmdl_view
   endif
-  call cursor([a:end, 1])
   if !empty(a:pattern)
     call s:search(a:pattern, 'c', a:end, s:search_timeout_remaining)
   endif

Why does it need this?

markonm commented 5 months ago

The plugin previews the range by moving the cursor to the end of the range. The cursor is moved only when Command-line mode is active. After the preview is over, the cursor is restored to its original position.

If you don't like that behavior, try adding the following to your vimrc:

let g:traces_preserve_view_state = 1
KSR-Yasuda commented 5 months ago

@markonm Thank you, it was fixed with this option!