0

Suppose that I have a map on my init.vim that I want to change the behaviour depending on the folder that I am. How could you do that?

A more concrete example: I have a map on my F12 that runs the project that I am. So if I am on a python project, this F12 will run an ipython on a floaternew window, with the current file already imported. Though, if I am on a cpp project, the same F12 will build using Make and running the binary on a floaternew window as well.

Nowadays, I have these two behaviours mapped on different key bindings. But It is going to very nice if I have only one binding to "run the project". Even if I need to open neovim with some parameter in each project, like neovim --local-config mylocalconfig.vim (extending init.vim with some behaviour)

I am kind inspired by a behaviour like direnv but with .vim files.

Any ideas?

romainl
  • 186,200
  • 21
  • 280
  • 313
user3692586
  • 199
  • 1
  • 7
  • 1
    https://www.vim.org/scripts/script.php?script_id=727 , https://www.vim.org/scripts/script.php?script_id=3393 Found in https://www.vim.org/scripts/script_search_results.php?keywords=local+project&script_type=utility&order_by=rating&direction=descending&search=search – phd Dec 23 '21 at 15:33
  • 1
    For language-dependent settings you'd better use filetype-plugins: http://vimdoc.sourceforge.net/htmldoc/filetype.html – phd Dec 23 '21 at 15:35

1 Answers1

1

There is an option in vim set exrc which enables reading vim config files from current directory, it also works in neovim.

From docs (:h exrc)

Enables the reading of .vimrc, .exrc and .gvimrc in the current directory. If you switch this option on you should also consider setting the 'secure' option (see |initialization|). Using a local .exrc, .vimrc or .gvimrc is a potential security leak, use with care! also see |.vimrc| and |gui-init|. This option cannot be set from a |modeline| or in the |sandbox|, for security reasons.

Update, since neovim 0.9.0 exrc option will look for init.lua first and afterwards will check for .nvimrc.

Monsieur Merso
  • 1,459
  • 1
  • 15
  • 18