Does anyone know of a shorter, happier way to perform (in normal mode)
Pdwbyw That is, replace the current word with whats in "0 but leave "0 alone?

        "_cw^R0<esc>

where ^R is control+R and <esc> is an actual escape.

While it's not shorter, it tends to behave more predictably by my arbitrary definition of "predictable". Two edge cases would be

1) if your "0 happens to have non-word characters in it or
2) your cursor is on the last character of the word (or on a one-character word, which by definition, puts you on the last character thereof)

...which may qualify for the "happier" part of your query, if not for the "shorter" part.

It also has the advantage that it's

1) simple to map because it's "predictable" (as per above) (okay, yours was simple to map, but had some eyebrow-raising behaviors in odd edge cases that would be an annoyance to track down in a mapping)

        :nnoremap <f4> "_cw<c-r>0<esc>

2) and easy to expand to any text object, such as the whole word the cursor is in, even if you aren't at the beginning of it:

        :nnoremap <f4> "_ciw<c-r>0<esc>

where the "iw" is an "inner word" that could be any text object

        :help text-object

Hope this gives you some ideas for working faster/better.

-tim



Reply via email to