My .vimrc contains this snippet:

nnoremap S :%s//g<LEFT><LEFT>

It creates a key binding which means that when I'm in normal mode, I can:

  1. type the character S
  2. type the string find/replace
  3. hit Enter, which replaces all occurrences of find in the current buffer with replace
  4. return to normal mode

I'd like similar functionality in Spacemacs. Prefixing the command with Space is fine. How do I do it?

1 Answer 1


Here is a snippet to do it:

(defun my-global-ex-search ()
  (let ((evil-ex-substitute-global t))
    (evil-ex "%s/")))
(define-key evil-normal-state-map "S" 'my-global-ex-search)

The idea is to define an interactive function (can be called by the user) to call evil-ex with the initial input and evil-ex-substitute to t. Then we bind this function to S in the normal state keymap.

EDIT: added support for /g

  • Eh, typing the /g isn't that hard. Thanks! Commented Nov 23, 2015 at 15:07
  • @hoosierEE in this case you can remove the let form and just put (evil-ex "%s/") in the function body.
    – syl20bnr
    Commented Nov 23, 2015 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.