Acting on multiple files

First off want to say I love the idea of kakoune. That it tries to do one thing well and be easily extensible really speaks to me. As an avid neovim user, I’ve been trying to evaluate the pros and cons of switching, and right now the big one for me is the ability to replay a macro against a bunch of different files. Being able to record a complex macro, load up all my targets in args and execute the macro either in parallel (argdo) or in series (advance to next file as part of the macro) has proved invaluable refactoring files, especially on larger codebases. I’d rather learn one tool and learn it well, so having to revert to vim for changes like these might be a deal breaker for me. So I’d love to hear the communities take on this, and potential solutions.

Thanks in advance!

I actually use a pattern of grep + macro a lot for stuff like this. Here is an asciicast asciicast of me doing it.

Basically, I make the Q recording:

  1. Go into the file
  2. Do the edit on that line (which :grep took me to)
  3. Walk back to the grep buffer
  4. Go down one line

With those four steps, I can just hit “q” to make a change on the line I am looking at (so you can skip some) and I can do 10q or (lines_in_grep_buffer)q to do them all.

There is also a good plugin https://github.com/occivink/kakoune-find that allows you to find/replace over all open buffers.

1 Like

Thank you so much for the quick reply! That’s a really nice way of going about it, I really like that it is leveraging a workflow that would be familiar outside of the editor using grep (which kakoune seems very good at generally). I will definitely give this a try later today.

This is slightly off topic but have you found things that vim could accomplish that would be difficult/impossible in kakoune? I would assume that since a lot of the people working on kakoune have used vim they would have filled those gaps, but I find that some of the more powerful parts of vim (this for example) aren’t always widely known.

Again thanks so much for your detailed response, I am a lot more excited to use it now that I know that some of the complex workflows in vim are even simpler in kakoune!

There are a lot of rough edges compared to stuff in vim, but once you get used to using the command line tools *nix provides it becomes easier (and your knowledge more generalized).

A big example is incrementing numbers, which you can do with a plugin (https://gitlab.com/Screwtapello/kakoune-inc-dec) or you can learn to do it using a console tool bc, and once you do – you might enjoy the elegance of it.

asciicast

Yeah I really like how it leverages an existing ecosystem that’s valuable in its own right. It would be difficult to compete if it was trying to encompass all the things vim does, but by easily integrating with other tools kakoune will hopefully age better than vim has. If the line numbering is an example of a rough edge then I’m sold, that seemed way more elegant than the editor-specific knowledge I’d use to accomplish the same task in vim.

Thank you, Robert. Love to see those recordings. Could you please name the commands/registers you are using? Some of them I definitely don’t know.

Thanks!

Time to watch video and try to remember…

Will update the older posts.

1 Like