How do I simply replace a visual mode selection I've made in Vim with any amount of new words?

Today, I'm in a line and need to replace a few words to clarify an idea, like so:

Superuser is THIS IS THE TEXT I WANT TO REPLACE awesome.

After visual selection, however, being the novice I am, I hit r and type my intended replacement text:

Superuser is aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa awesome.

Uh oh! It's singularly replaced every character position of my visual selection with exactly just the first letter of the intended text I wanted as a replacement. Would a modifier help maybe? Shift R? Nope. What gives?

2 Answers

Use c to change, in lieu of r to replace. Having made my visual selection, keying c, I can type whatever I want, and I'm all good.

Superuser is absolutely awesome.

The only caveat I might add for my experience was that advancing my visual mode selection with w also took the first character at the end of my selection of the text that I did not want to be affected. The solution I found for this was to advance my selection using e in lieu of w, to trim the selection more properly to the end of the word. Hope this helps somebody.

From :help v_r:

 {Visual}r{char} Replace all selected characters by {char}.

Trying random keystrokes is not exactly the best way to learn Vim, or any comparably feature-rich program for that matter.

Instead, here is a more fruitful approach:

  1. If you didn't already, do $ vimtutor as many times as needed to get the basics right.
  2. As instructed at the end of vimtutor, level up to the user manual :help user-manual. It will guide you progressively through every feature, from basic to advanced. This not a novel: go at your own pace, skip chapters, come back to them later, and, most importantly, experiment along the way.
  3. Keep an eye on anti-patterns and inefficient actions, find improvements, practice. Rinse. Repeat.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like