Fork me on GitHub
#vim
<
2020-10-08
>
dharrigan08:10:50

Started to use tpope/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

dharrigan08:10:06

❯ cat .projections.json                        
{
  "src/*.clj": {
    "alternate": "test/{}_test.clj",
    "type": "source"
  },
  "test/*_test.clj": {
    "alternate": "src/{}.clj",
    "type": "test"
  }
}

🚀 3
practicalli-john20:10:02

Do I understand correctly that I need to add this configuration to every Clojure project I work with (I have lots).

practicalli-john20:10:10

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 :)

dharrigan07:10:04

I can certainly give that a try soon!

dharrigan08:10:28

create a file $HOME/.vim/syntax/clojure.vim

dharrigan08:10:37

then add in this:

dharrigan08:10:53

"
" Projections
"
autocmd User ProjectionistDetect
  \ call projectionist#append(getcwd(),
  \ {
  \   'src/*.clj': {
  \     'alternate': 'test/{}_test.clj',
  \     'type': 'source'
  \   },
  \   'test/*_test.clj': {
  \     'alternate': 'src/{}.clj',
  \     'type': 'test'
  \   },
  \ })

dharrigan08:10:16

bingo. only files of type clojure will have that applied, allowing projectionist to work as appropriate.

practicalli-john09:10:56

Excellent, thank you for sharing and improving my vim life

dharrigan10:10:33

You're most welcome 🙂

dharrigan08:10:53

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 🙂

practicalli-john20:10:35

Spacemacs uses SPC p a for alternating between src and test in a project, so I would probably use that myself.

dharrigan08:10:03

pretty handy!