tags:

views:

63

answers:

3

There's a command in VIM where you can say how many chars to replace, and VIM will put a "$" at that many characters out, and you can type in the replacement for those characters. The original and new text can be different lengths. What's the command for this?

A: 

The command is s. In your example, it would be 6s.

Greg Hewgill
+1  A: 

It is the behavior of c command when 'cpoptions' contains $ (so it is a default behavior for vi and some configurations of Vim).

wRAR
I just tried '`:set cpoptions="aABceFs$"`' (to add '$' to what was already there) and it didn't seem to make any difference. Is that what was expected to make the difference. (Vim 7.2 on MacOS X 10.6.2.)
Jonathan Leffler
Works here. Check that 'cpoptions' still contains $.
wRAR
You shouldn't use quotes in the value, here your command just cleared `'cpoptions'`.
wRAR
This is correct, and if you want to simply try adding $, use set cpoptions+=$4c will now work as requested.
Sarah
@Sarah (and wRAR): thanks - when I used `cpoptions+=$`, then it worked.
Jonathan Leffler
A: 

The nearest I can think of is '6s'; that deletes the next 6 characters and leaves you in insert mode, but it doesn't show a '$' at the end - it just removes the material.

Jonathan Leffler
Depending on your terminal and version of vi(m), it used to be that the editor wouldn't go to the trouble of sliding the rest of the text to the left right away, and would place a `$` at the end of what you were changing. When you left insert mode, then the remaining text would be redrawn to match the amount you typed. These days I usually only see that on old `vi` installations.
Greg Hewgill
That sounds plausible and faintly familiar...vi over a 14.4 kilobaud/s connection? 9.6 kb? There were advantages to 'ed' at those speeds. And yes, I did sometimes work over such slow connections, but it was a long time ago.
Jonathan Leffler