3

What does the r cpoptions flag do? Via :help cpo-r:

Redo ("." command) uses "/" to repeat a search command, instead of the actually used search string.

I understand that . repeats the last change, but I don't understand how search is involved.

Can you give me an example of how cpoptions-=r and cpoptions+=r behave differently?

1
  • Welcome to Vi and Vim! Commented May 26 at 6:37

1 Answer 1

5

Let's assume you just performed the following theoretically dot-repeatable command, which involves search:

d/foo<CR> 

After that, you moved the cursor somewhere else:

/three<CR> 

where you want to repeat the last deletion:

. 

With cpoptions-=r, doing . will repeat the command exactly as typed: the text from the cursor to the next foo is deleted:

cpo-r

  • The dot-repeatable command is supposedly d/foo<CR>,
  • the dot-repeated command is indeed d/foo<CR>.

No surprise.

With cpoptions+=r, the command reuses the last search, in this case three, not the one you used in the supposedly dot-repeatable command:

cpo+r

  • The dot-repeatable command is presumably d/foo<CR>,
  • the dot-repeated command is actually d/three<CR>, not d/foo<CR>,
  • so the dot-repeatable command was actually more like d//: "delete until next match of the last search pattern" instead of "delete until the next foo".

Surprise!

This behavior was somewhat expected in Vi but it was (rightfully, might I say) considered unintuitive and thus improved in Vim while leaving an escape hatch for people who preferred the Vi way. That is the whole point of :help 'cpotions'.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.