Started to use tpope/projectionist
<https://github.com/tpope/vim-projectionist>
which allows me to swap between src and test with a simple binding, for example, here is my .projections.json
configuration which lives at the root of the project
❯ cat .projections.json
{
"src/*.clj": {
"alternate": "test/{}_test.clj",
"type": "source"
},
"test/*_test.clj": {
"alternate": "src/{}.clj",
"type": "test"
}
}
Do I understand correctly that I need to add this configuration to every Clojure project I work with (I have lots).
Reading the vim-projectionist docs, it seems you can set it globally if a directory contains a file, using g:projectionist_heuristics
I wonder if that would work if we look for a deps.edn file in the root of a project, this could save putting a json file in every project.
If you try this approach, let me know if it works. Its on my very long neovim todo list :)
I can certainly give that a try soon!
This works
create a file $HOME/.vim/syntax/clojure.vim
then add in this:
"
" Projections
"
autocmd User ProjectionistDetect
\ call projectionist#append(getcwd(),
\ {
\ 'src/*.clj': {
\ 'alternate': 'test/{}_test.clj',
\ 'type': 'source'
\ },
\ 'test/*_test.clj': {
\ 'alternate': 'src/{}.clj',
\ 'type': 'test'
\ },
\ })
bingo. only files of type clojure will have that applied, allowing projectionist to work as appropriate.
.
Excellent, thank you for sharing and improving my vim life
You're most welcome 🙂
if one follows normal naming conventions, then swapping between your src file and the test file can be bound to a key, for example ,t
if ,
is your leader 🙂
Spacemacs uses SPC p a
for alternating between src and test in a project, so I would probably use that myself.
pretty handy!