1. Frank Fischer
  2. evil
  3. Issues
Issue #236 wontfix

# and * on selection

Piotr Kordy
created an issue

# and * search are very useful. In visual mode, when something is selected, it would be nice if they would search for selected thing instead of word under cursor. It would integrate nicely for example with expand-region extension.

Comments (6)

  1. Piotr Kordy reporter

    As a workaround I assign to * in visual state the following function:

     (defun search-selection-forward (beg end)
       "search for selected text in forward direction"
       (interactive "r")
       (when (evil-visual-state-p)
        (let (
             (selection (buffer-substring-no-properties beg end))
             )
          (evil-exit-visual-state)
          (setq isearch-forward t)
          (evil-search (regexp-quote selection) t t))))
    
  2. Frank Fischer repo owner

    This will probably never be the default, because it's not the default in Vim. But it should not be too difficult to write a simple command that implements exactly this behaviour (ahh, almost what you did, although not compatible with evil's own search module ;)).

    But I think we should clean up the search code a little bit so that such function easily works with both search modules (currently there is not well-defined API for starting a new search, it's somehow hard coded in the commands).

  3. Piotr Kordy reporter

    The evil-search-next works afterwards and I stopped improving code after getting this functionality. My lisp experience is not very deep (3 weeks deep to be precise). I tried to copy how evil-search-symbol calls evil-search, but I do not understand most of the code. So any improvements making the function more compatibile will be appreciated :).

  4. Log in to comment