I'm getting started using spacemacs with vim bindings for editing and one thing I would like to do sometimes is replace some text with some other text. For example I might have

k x = (1 + 1) * x

and I want to select replace (1 + 1) with 2. Normally in vim I would just type f(v%s2<Esc>.

However in spacemacs s doesn't work on selections like it does in vim, this instead puts 2 around the selection

k x = 2(1 + 1)2 * x

Which is not what I wanted. (Strangely s seems to work perfectly in normal mode)

Now obviously in this case I can just do di to delete and enter insert mode separately but in general di has some important drawbacks:

  • It cannot be repeated across several lines using visual selection mode (a very common use case)
  • It cannot be repeated with . since it is two actions.

Is there another option that I could use to achieve the functionality of my old s? Or do I have to modify my configs somehow?


Let me just preface this by saying that I am not very familiar with spacemacs except for the fact that it is similar to vim so I might be missing emacsy solutions. That being said, a friend of mine who uses spacemacs tested these suggestions for me and has confirmed that they work.

You can just use the exact sequence you have been using but replace the s with a c. (As in f(v%c2<Esc>). You can also achieve the same effect without visual mode with the c command with the motion ab which is the motion over the whole of a parenthetical. Combined with the f command to reach the start of the parenthetical the whole set of commands would be f(cab2<Esc>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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