Fork me on GitHub
#vim
<
2021-01-29
>
orestis13:01:03

I am in need to do a refactoring across many files. Go from (defn foo [{:keys [show]}] …) to (defn foo [{:keys [showing]}] …), so essentially rename an argument of a function and its callers. Is this something clojure-lsp could provide?

dave14:01:00

I don't know the answer to that question, but I do feel like sharing the way that I typically handle things like this, because I think it's a nice, pragmatic solution and I've never found it cumbersome, even in large code bases. I use https://github.com/dyng/ctrlsf.vim to search for all instances in the code base of a unique (or as close as I can get to unique) string. Then, I either go through and fix them one at a time, or if there are a ton of them, I might do %s/thing/replacement/g in the results buffer, which ctrlsf handles nicely by saving my changes to each file. I find ctrlsf utterly indispensable. I use it so often that I've defined a couple of mappings for convenience: <leader>f runs :CtrlSF<space> so that I can type in the string I have in mind and press enter. In visual mode, <leader>f runs :CtrlSF <my selection><Enter> so that I can highlight one instance and search for all instances across the code base.

1
samoleary14:01:32

I use a similar approach with https://github.com/junegunn/fzf and https://github.com/junegunn/fzf.vim, complete with a couple of custom mappings too 👌

💯 1
dave14:01:29

It's also a nice solution because it works in any code base in any language, not just Clojure.

dave14:01:35

Another thing I'll do on rare occasions where there are a ton of instances and the replacement is straightforward, is write a Bash script using find and sed -i

samoleary14:01:05

I don't think clojure-lsp can do that yet @orestis. This is returned when I try to rename keys in a map or keys that are being destructured: [coc.nvim] Invalid position for rename

orestis15:01:16

I also use fzf together with the quickfix window to visit multiple files, but I confess that for this instance I went into vscode and used the mouse 🙂

dharrigan15:01:53

bufdo is my goto