Suppose I have one line:

Linux is not_ Linux

My cursor lies on the _ mark and I want to replace the second Linux to Unix,how can I do that in vim?


Try the following key sequence:

c e Unix Esc (note the space character before "Unix")

Here's a brief explanation:

  • c: "change" command, similar to delete but ends in "insert" mode.
  • e: from the cursor to the end of the following word.
  • " Unix": the replacement text
  • Esc: Return to command mode (always return to command mode!)
  • Sorry, what does it mean? – xiaohan2012 May 10 '12 at 3:04
  • @xiaohan2012 Those are fairly basic vim commands. It means "change text to end of word", type "space Unix", and "esc" key to exit Insert mode. If you are unfamiliar with vim, learning it enough to use it fluently does take a non-trivial amount of time. If you are willing to do that, start with the vimtutor command. – jw013 May 10 '12 at 3:12
  • Thanks. But this is not replacement. Any hint on using replacement? – xiaohan2012 May 10 '12 at 3:16
  • 3
    @xiaohan2012 I answered the question you posted, by giving you something that would replace the word Linux with the word Unix assuming the cursor position you gave. I don't think replace means what you think it means. If you are talking about vim's replace commands r and R, they are not the best choices to use here. If this is not what you are looking for, then ask the right question to get what you want. – jw013 May 10 '12 at 4:33
  • 4
    @xiaohan2012 Just do the vimtutor once and you know or have seen all these commands – Bernhard May 10 '12 at 5:40

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.