Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions evil-search.el
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ one more than the current position."
(evil-flash-search-pattern string t))))

(defun evil-search-word (forward unbounded symbol)
"Search for word near point.
"Search for text in visual selection if in visual mode
otherwise search for word near point.
If FORWARD is nil, search backward, otherwise forward. If SYMBOL
is non-nil then the functions searches for the symbol at point,
otherwise for the word at point."
Expand All @@ -288,7 +289,9 @@ otherwise for the word at point."
(not (string= string "")))
(evil-search string forward t))
(t
(setq string (evil-find-thing forward (if symbol 'symbol 'evil-word)))
(setq string (evil-find-thing-or-visual-selection
forward
(if symbol 'symbol 'evil-word)))
(cond
((null string)
(user-error "No word under point"))
Expand Down Expand Up @@ -328,6 +331,23 @@ e.g. `symbol' or `word'. If FORWARD is nil, search backward,
otherwise forward. Returns nil if nothing is found."
(car (evil--find-thing forward thing)))

(defun evil-find-thing-or-visual-selection (forward symbol)
"Return text in visual selection if in visual mode and
if `evil-ex-search-nvim-visual-word-search' is set to t,
otherwise return evil-find-thing with FORWARD and SYMBOL as
parameters"
(let (string)
(if (and
evil-ex-search-nvim-visual-word-search
(evil-visual-state-p))
(progn
(setq string (substring-no-properties
(buffer-substring (region-beginning)
(1+ (region-end)))))
(evil-exit-visual-state)
string)
(evil-find-thing forward (if symbol 'symbol 'evil-word)))))

(defun evil-find-word (forward)
"Return word near point as a string.
If FORWARD is nil, search backward, otherwise forward. Returns
Expand Down
8 changes: 8 additions & 0 deletions evil-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,14 @@ highlighted."
:type 'boolean
:group 'evil)

(defcustom evil-ex-search-nvim-visual-word-search nil
"If t enable neovim-style visual search when calling
`evil-search-word' i.e. selected text in visual mode shall be
searched instead of `thing-at-point', otherwise search for
`thing-at-point'"
:type 'boolean
:group 'evil)

(defcustom evil-ex-substitute-highlight-all t
"If t all matches for the substitute pattern are highlighted."
:type 'boolean
Expand Down