Skip to content

Instantly share code, notes, and snippets.

@martinhj
Last active October 23, 2017 20:34
Show Gist options
  • Save martinhj/2db31ba0644d22b7775bbc91f1ce706d to your computer and use it in GitHub Desktop.
Save martinhj/2db31ba0644d22b7775bbc91f1ce706d to your computer and use it in GitHub Desktop.
vim and project specific config

vim and project specific config

I've been in a few .php/.js-projects lately where it is not straight forward to use gf ("goto file"). Usually when the cursor in vim is above a filename I simply hit gf and it opens that file for reviewing/editing.

But in webdev land where I have been lately it is not untypically to do a reference to a file of sorts:
{% include '\_partials/main-menu' with {id: mainMenu} %}

It states the path _partials/main-menu, but the file that I want to investigate is craft/templates/_partials/main-menu.twig.

To gf my way to the right file I found that I could set path+=$PWD/craft/templates and set suffixesadd+=.twig

But I do not want to enable this to all the files I'm editing, so I use setlocal path and setlocal suffixesadd instead. At the same time I don't want to type this in every time I open a file. And I do not want it to happen for all the .twig files I edit. To fix this I added silent! so ../vimlocal.vim to my vimrc.

In the ../vimlocal.vim file I put the Filetype check I put

autocmd Filetype html.twig setlocal path+=$PWD/craft/templates
autocmd Filetype html.twig setlocal suffixesadd+=.twig

Now it is important to open vim in the project root directory (or to both get the ../vimlocal.vim-path right and the path= to point in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment