This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-29
Channels
- # announcements (13)
- # aws-lambda (19)
- # babashka (11)
- # beginners (90)
- # calva (35)
- # chlorine-clover (16)
- # cider (8)
- # clj-kondo (6)
- # cljsrn (10)
- # clojure (44)
- # clojure-australia (1)
- # clojure-europe (35)
- # clojure-nl (6)
- # clojure-norway (7)
- # clojure-uk (101)
- # clojurescript (79)
- # community-development (40)
- # conjure (1)
- # contributions-welcome (4)
- # core-logic (2)
- # cursive (6)
- # datomic (4)
- # figwheel-main (5)
- # fulcro (18)
- # girouette (1)
- # graalvm (3)
- # hoplon (2)
- # hugsql (2)
- # jobs (5)
- # malli (26)
- # off-topic (74)
- # pathom (36)
- # portal (4)
- # reagent (10)
- # reitit (23)
- # remote-jobs (1)
- # shadow-cljs (27)
- # spacemacs (10)
- # sql (3)
- # startup-in-a-month (6)
- # tools-deps (55)
- # vim (11)
- # xtdb (15)
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?
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.
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 👌
It's also a nice solution because it works in any code base in any language, not just Clojure.
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
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.Sorry, I missed the clojure-lsp
part.
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
there is also bufdo: https://www.freecodecamp.org/news/how-to-search-and-replace-across-multiple-files-in-vim/