Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting range moves cursor #1

Closed
tmilloff opened this issue Sep 20, 2017 · 7 comments
Closed

Highlighting range moves cursor #1

tmilloff opened this issue Sep 20, 2017 · 7 comments

Comments

@tmilloff
Copy link

When a range is highlighted, the cursor moves to the last line of the range until the command is executed. When using relative numbering this makes it hard to use commands like :t and :m, since the displayed relative numbers will change, but vim will still expect the relative numbers as displayed before the highlighting moves the cursor.

Is it possible to make a fix to keep the cursor position on the same line during the highlight, or alternatively create a setting to disable range highlighting for certain commands?

@markonm
Copy link
Owner

markonm commented Sep 20, 2017

Cursor position is always restored after highlighting. See here. Try to comment out that line and let me now if that's the behavior you want.

@tmilloff
Copy link
Author

The cursor position is restored after pressing Enter to complete the command, but not immediately after the highlighted range is created. Commenting out that line merely prevents the cursor position from ever being restored.

@markonm
Copy link
Owner

markonm commented Sep 20, 2017

Please provide steps to reproduce. I don't use numbers at all so I'm having hard time grasping the issue.

@markonm
Copy link
Owner

markonm commented Sep 21, 2017

What delimiter are you using when the issue happens? I you use ; cursor will be moved but if you use , it will not be moved.

Take a look at: h :;

@tmilloff
Copy link
Author

Sorry for such a late reply. Here are a couple recordings that show the issue.
This recording shows the behavior without the plugin.
This other recording shows the behavior with the plugin. Note that after entering the range and move command, the relative line numbers change. However, when I hit enter, the command still works the same as it does without the plugin. This means that I need to remember which line to move to before I finish typing the range and command.

@markonm
Copy link
Owner

markonm commented Oct 27, 2017

I uderstand now. You can achieve that behavior with the following:

diff --git a/plugin/traces.vim b/plugin/traces.vim
index 77e23b1..1c25aa5 100644
--- a/plugin/traces.vim
+++ b/plugin/traces.vim
@@ -523,6 +523,7 @@ function! s:highlight(pattern_regex, selection_regex, last_specifier_pattern, ab
     silent! call s:set_cursor_position(a:pattern_regex, a:selection_regex, a:abs_range)
   endif
 
+  call cursor(s:cursor_initial_pos)
   redraw
 endfunction

I could add an option, but that approach has a flaw. Patterns and ranges which are not present on starting screen will not be highlighted. Perhaps, it's better to utilize newly introduced autocommands, CmdlineEnter and CmdlineLeave, to turn off relative numbers when inside command-line?

@tmilloff
Copy link
Author

Thanks so much for your quick response! I confirm that does indeed fix the problem. Could you add it as an option, turned off by default? I like that behavior despite not highlighting patterns and ranges on the starting screen, and perhaps others will as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants