hauleth/sad.vim

Re-using the recent change?

097115 opened this issue · 1 comments

In my .vimrc, I have the following:

nnoremap {lhs} :let @/ = '\<' . @" . '\>'<CR>/<CR>cgn<C-r>.<Esc>
nnoremap {lhs} :let @/ = '\<' . @" . '\>'<CR>?<CR>cgN<C-r>.<Esc>

I.e., if I changed a word and later decided that it would be great to apply the same change to other instances of this word, then this mapping allows me to do that.

Speaking of sad.vim, may be it's worth to add something like this? The possible scenarios:

  • applying the recent change (made not with sad.vim) to the same word: we press s (or a user defined key(-s)) + some custom "motion" created for this occasion, like rc (which, of course, is not a real motion like iw but simply a custom hotkey that is obviously available because we only use s with motions), and this picks up the word we changed from the register @", applies the change from the register @. and via some sad.vim magic makes this repeatable with . :)
  • applying the recent change to another word or selection, which is almost the same, except it's either picks up the word under the cursor, or the current selection.

What do you think?

About 1. If I understand correctly you want to replace text with content of the register, then you can go with s{motion}<C-r>{register}<Esc> and then it will be repeatable.

About 2. I do not quite get what you expect there, but if you want to repeat change on text object instead of text in that object then you can use c{motion}.