there has been some discussion of the relative editing power of Kakoune and Vim/Neovim. I always thought that anything that Kakoune does with multiple selections could be duplicated in Vim with search-and-replace plus macros.
Yet, I recently had to perform the following editing task: replace each occurrence of “execute-keys” by “exec”, but only in lines with “printf” inside.
In Kakoune, this is a piece of cake: select the whole buffer, split on line returns, keep only the lines with “printf”, select “execute-keys” and replace with “exec”.
But in Vim… how could one do this? (Suffering from PTSD = Post-Traumatic vimScript Disorder, I can barely recall anything about Vim.) Macros do not have conditionals inside, so would macros be of any help?
Hmm… thinking twice, there always seems to be an equivalent with macros. It would be nice to find something doable in bare-bones Kakoune that cannot be done in bare-bones Vim, but pending this, we can at least note that the Kakoune solution is much easier (with constant visual feedback).
What about replacing A with B in every paragraph that contains C and D?
One cannot search for a C .+ D regex and then select the containing paragraph (because there is no guarantee that this paragraph is one and only one), then select A and replace with B.
Replacing by C the second occurrence of B that occurs in any line that contains A. (I think ex’s substitution command works only on the first occurrence or on all of them.)
Edit: not doable with :g, but doable with macros, I guess. My two previous suggestions do stand – at least I hope!
Rotating function arguments seems to be painful in all but the simplest cases in barebone vim.
For simple cases, in kakoune, we can just split on commas and rotate selection. For more complex cases, we can use an object selection mode ( or , followed by u for argument).
Painful, definitely, but still doable with regex searches and two named registers (one to save the first argument, the other to save the second argument).
Along my rambling, I think I found two valid examples that are a piece of cake in bare-bones Kakoune and impossible (not just painful) in bare-bones Vim:
(1) replacing A with B in every paragraph that contains C and D
(2) replacing A with B in every line that contains C but not D
The second example relies on Kakoune’s structural-regex facility for excluding the selections that do not match a given regex.
I hope I’ll get more feedback from the list about these examples, otherwise I might ask for help on a Vim/Neovim list.
This topic is important because it would establish that Kakoune’s model of selection first is objectively superior, in some significant respects, to Vim’s action-first. For a while I have been thinking of replying to the “Why not Kakoune” section in this post: