3

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

5

Here is a snippet to do it:

(defun my-global-ex-search () (interactive) (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

1
  • @hoosierEE in this case you can remove the let form and just put (evil-ex "%s/") in the function body. Commented Nov 23, 2015 at 15:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.