Is it possible to start insertion in the beginning of a word when standing in the middle of it with a single keystroke? Currently I am using bi or Bi, but it does not allow me to use . to repeat the same action.
I really love A and I which operate with a line. I am looking for alternative commands which operate with w and W. I was able to find a replacement for ea and Ea, see
How to append to the end of word with one key stroke? However, its not so easy for bi and Bi.
Let's say we have these lines:
random_name: SomeKindOfType = "foo"
long_name: AnotherType = "bar"
short_name: ThirdType = "spam"
And I want to add a prefix for all the types. When standing in the middle of SomeKindOfType I would like to press a single keystroke, write My prefix and then repeat the same insertion two times with j. to get this output:
random_name: MySomeKindOfType = "foo"
long_name: MyAnotherType = "bar"
short_name: MyThirdType = "spam"
I have unsuccessfuly tried defining my own command with repeat.vim plugin; it seems not to work with insertion commands such as i, a, c.
., the self-deleting autocommand would have to be set from within the singlecoperation, which it could by using<c-r>=to call a function that does so, but that expression wouldn't be re-evaluated by., so repeats wouldn't work. Maybe a permanent autocommand. – JoL Jan 12 '22 at 19:10InsertLeave normal! "-p(Might need an execute to avoid that double-quote showing as a comment). That’s not going to be good for a permanent thing. OTOH with tpope’s repeat plugin, I think making it repeatable is far easier, but possibly not perfect. – D. Ben Knoble Jan 12 '22 at 19:51nmap <leader>i cb<c-r>=execute('au InsertLeave * ++once normal "-p')<cr>. However, while that would work when invoking with\i, it wouldn't when trying to repeat it with.. It would just put the prefix you insert without restoring the part that was deleted, because vim seems to save the result of the=expression instead of re-evaluating for each call of., so you only get the autocommand set-up on the first time. – JoL Jan 12 '22 at 20:04nmap, to only act on those. Also, yes, it may be easier to modify tpope's script. For all I know, the decision to require appending instead of prepending the function call may have been arbitrary, and the switch could be relatively simple. – JoL Jan 12 '22 at 20:14:, possibly in a function. Would be easier. – D. Ben Knoble Jan 12 '22 at 21:20.? – JoL Jan 12 '22 at 21:22