# and * on selection

Piotr Kordy avatarPiotr 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

    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))
          (setq isearch-forward t)
          (evil-search (regexp-quote selection) t t))))
  2. Frank Fischer

    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

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.