Vim Cartographe is a plugin aiming at simplifying the navigation in a project. Given a configuration, you'll be able to jump between file whose path is defined by common variables.
You may want to install FZF as a plugin to enable FZF splits.
I recommend using vim-plug as a plugin manager. From there, simply add
Plug 'baspar/vim-cartographe'
to your plugin list
The configuration is a nested dictionary which key can be folder (ending with /
, or files).
Values can be a file type, or nested dictionary, which will be interpreted as a nested path. Cartographe is going to try to fill up intermediate paths if needed. For example:
{
\ 'src/main/': {
\ '{NAME:pascal}/{NAME:camel}.js': 'index'
\ },
\ 'src/test/': {
\ '{NAME:pascal}/{NAME:camel}.js': 'indexSpec'
\ }
\ }
Will match the files src/main/components/Layout/layout.js
, and src/tests/components/Layout/layout.spec.js
, and you'll be able to navigate between them, despite the components
folder not mentionned in the configuration
Variables can be specified following the format {NAME}
or {NAME:format}
, and the available format are:
pascal
for PascalCasecamel
for camelCasesnake
for SNAKE_CASEkebab
for kebab-case
let g:CartographeMap =
\ {
\ 'src/main/components/': {
\ '{NAME:pascal}/index.js' : 'index',
\ '{NAME:pascal}/stories.js' : 'stories',
\ '{NAME:pascal}/{NAME:pascal}.js' : 'pure',
\ '{NAME:pascal}/styledComponents.js' : 'styled'
\ },
\ 'src/main/redux/': {
\ '{NAME:pascal}/saga.js' : 'saga',
\ '{NAME:pascal}/reducer.js' : 'reducer',
\ '{NAME:pascal}/selector.js' : 'selector',
\ '{NAME:pascal}/api.js' : 'api',
\ '{NAME:pascal}/action.js' : 'action'
\ },
\ 'src/test/components/': {
\ '{NAME:pascal}/index.spec.js' : 'indexSpec',
\ '{NAME:pascal}/{NAME:pascal}.spec.js' : 'pureSpec',
\ '{NAME:pascal}/styledComponents.spec.js' : 'styledSpec'
\ },
\ 'src/test/redux/': {
\ '{NAME:pascal}/saga.spec.js' : 'sagaSpec',
\ '{NAME:pascal}/reducer.spec.js' : 'reducerSpec',
\ '{NAME:pascal}/selector.spec.js' : 'selectorSpec',
\ '{NAME:pascal}/api.spec.js' : 'apiSpec',
\ '{NAME:pascal}/action.spec.js' : 'actionSpec'
\ },
\ 'src/test/fixtures/{NAME:camel}/{NAME:camel}.js' : 'fixtures'
\ }
:CartographeNav
Will open a FZF window with the list of all files. They'll appear in in white if existing, and in grey if they do not exist yet.
You select multiple file with tab
, open them with enter
, <C-x>
or <C-v>
(Vertical and horizontal split)
-
:CartographeNav pureSpec
Will open the file of typepureSpec
in the current window -
:CartographeNavS pureSpec
&:CartographeNavV pureSpec
Will open the file of typepureSpec
in a vertical/horizontal split -
:CartographeExec !npm run test {NAME:pascal}
Will run the given command after injecting file variables
Since configuration are project specific, you should either:
- Add the configration to your repo
.vimrc
and to activateset exrc
- Create a
vimrc
file not tracked by your VCS, and source it manually, e.g.:" In ~/Repo/.git/vimrc let g:CartographeMap = {} " in ~/.vimrc if filereadable(getcwd() . '/.git/vimrc') execute 'source' getcwd() . '/.git/vimrc' endif