Skip to content

Conversation

@thalesmello
Copy link

This pull request:

  • Makes the first start keypress immobile
  • Makes the second star behave just like a regular star press, moving to the next word.

Even though this changes a core intent of the plugin, which is to change how the star key works, it provides a sane default for people used to the old star behavior.

Let me know what you think.

@junegunn
Copy link
Owner

Thanks, I like the idea.

  • We should probably name the variable with b:slash_ prefix to avoid confusion/name clash.
  • Pressing * then # moves the cursor. Do you think it's desirable? Or should we make the user double-tap # to move?
  • Pressing * in visual mode leaves us in normal mode. A subsequent * will then select current word instead of the previous selection, but the cursor moves. I believe we can fix that by setting the value of the variable to a:seq[0:2] instead of 1 and compare it against the next a:seq.

@thalesmello
Copy link
Author

  • I submitted a new commit. Please take a look.
  • Regarding pressing * then # I think it makes sense. Sometimes I use * and # to navigate back and forth in a word. Would be a little bit weird to have to double press every time you want to change navigation direction. Plus, with the current behaviour, it looks like it's a "press * to get into search mode, and navigate with * or #. Plus, it's easier to implement.
  • I didn't notice it. I think it makes a lot of sense for * and # to keep on moving forward and backward. I've committed a prototype implementation. Works, but it's a little complicated, so I would like your feedback in the code, if possible.

@thalesmello thalesmello force-pushed the feature/repeated-star-movement branch from 0426d8d to b322817 Compare August 23, 2017 20:19
@junegunn
Copy link
Owner

Sometimes I use * and # to navigate back and forth in a word.

Makes sense, though I always use n and N, so it never occurred to me.

Here's a simpler patch.

diff --git a/plugin/slash.vim b/plugin/slash.vim
index 6b99444..2949564 100644
--- a/plugin/slash.vim
+++ b/plugin/slash.vim
@@ -30,14 +30,19 @@ function! s:wrap(seq)
 endfunction
 
 function! s:immobile(seq)
+  let class = len(a:seq[:2])
+  if get(b:, 'slash_prev_immobile') == class
+    return a:seq
+  endif
   let s:winline = winline()
+  let b:slash_prev_immobile = class
   return a:seq."\<plug>(slash-prev)"
 endfunction
 
 function! s:trailer()
   augroup slash
     autocmd!
-    autocmd CursorMoved,CursorMovedI * set nohlsearch | autocmd! slash
+    autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet! b:slash_prev_immobile | autocmd! slash
   augroup END
 
   let seq = foldclosed('.') != -1 ? 'zo' : ''

@thalesmello
Copy link
Author

@junegunn I believe your implementation and my implementation do different things, at least when I tried to test the behavior in my machine.

My intention was to simulate the * to go forward and # to go backward when they are used in visual mode. The way my commit d8974bd implements it, it works like this:

  1. Visual select the term you want to search
  2. Pressing * or # will take you to normal mode and activate the "star movement" keys
  3. In normal mode, pressing * takes the user to the next term, pressing # takes to the previous.
  4. When the user moves the cursor, it removes this special behavior, just like it removes the search highlight.

This is achieved by:

  • If visual star movement was activated by *, it means a forward search / was used, so * is redirected to n and # is redirected to N.
  • If visual star movement was activated by #, it means a backward search ? was used, so * is redirected to N and # is redirected to n.

The goal with this is to make it possible for users go star search using the * key to also use it for navigation.

@junegunn
Copy link
Owner

Oh, I see, thanks for clarification. I don't think I'm going to need it though, because I always use n and N to move between the matches and I've never tried or wanted to use * and # instead, so I don't want extra code. I suggest that you use your fork if it suits your needs. Thanks.

@junegunn junegunn closed this Aug 25, 2017
@thalesmello
Copy link
Author

@junegunn Just to let you know, in my fork of vim-slash (which I named vim-slasher), I've included some extra features, such as enhanced cgn substitution.

In case you're interested in taking a look: https://github.com/thalesmello/vim-slasher

@junegunn
Copy link
Owner

Cool, thanks for sharing. cgn stuff sounds like a nice improvement.

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

Successfully merging this pull request may close these issues.

2 participants