vim

For discussion on all things (neo)vim.
orestis 2021-01-29T13:51:03.019200Z

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?

dave 2021-01-29T14:32:00.024100Z

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
dave 2021-01-29T14:32:29.024700Z

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

dave 2021-01-29T14:33:35.025600Z

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

Jivago Alves 2021-01-29T14:54:13.028700Z

https://thoughtbot.com/blog/vim-macros-and-you Open all files w/ vim that match the pattern using grep:

vim $(grep pattern -rl .)
Then apply a macro that replaces things in vim, saves and goes to the :next file.

samoleary 2021-01-29T14:56:05.029600Z

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

samoleary 2021-01-29T14:56:32.029700Z

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
Jivago Alves 2021-01-29T14:58:34.030100Z

Sorry, I missed the clojure-lsp part.

orestis 2021-01-29T15:42:16.031800Z

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 🙂

dharrigan 2021-01-29T15:49:53.032100Z

bufdo is my goto