3

What's the best way to override my ftplugin settings for one project i.e. files under a specific directory?

For example, I have setlocal tabstop=4 in my ~/.vim/ftplugin/javascript.vim because all my company's projects have this whitespace policy.

But in one personal project I want to use tabstop=2 in my .js files.

I understand I can place a custom .vimrc in that project's directory and enable vim's exrc option to make it read that .vimrc file. Is this the best way?

acksys
  • 492
  • 3
  • 11
  • 1
    Your question is a duplicate of: http://stackoverflow.com/questions/456792/vim-apply-settings-on-files-in-directory?rq=1 – Luc Hermitte Apr 24 '13 at 17:46
  • Is it? I'm asking about overriding ftplugin behavior, not just the .vimrc file. – acksys Apr 25 '13 at 03:42
  • 1
    You're asking about overriding vim settings for files in a specific directory. Except you want to check the filetype before activating some settings, you'll get the same answers. The only thing missing in the other discussion(s), is that .exrc is limited to one directory while plugin-solutions change the settings in a whole hierarchy of directories. The distinction between overriding the .vimrc or a ftplugin quickly makes no sense: See the two _vimrc_local*.vim files here: https://github.com/LucHermitte/Rasende . They define project settings (project dirs, mappings, ...), – Luc Hermitte Apr 25 '13 at 11:02

2 Answers2

4

set exrc will read a .vimrc file in the current directory, but will also read the structure under .vim directory. So you can add

myproject/.vim/after/ftplugin/javascript.vim

to your project; It'll work as if this file were on your home dir when you open files from myproject dir.

Akobold
  • 936
  • 8
  • 25
  • Thanks. I know there are some concerns about security using this approach. Do you think this is the most secure way to do it? – acksys Apr 25 '13 at 03:45
  • @acksys: To be honest, I use this approach only for project specific syntax highlighting. – Akobold Apr 25 '13 at 14:19
  • There is a `set secure` option which attempts to prevent more dangerous code being executed from these local files, I think. – MichaelJones Dec 24 '14 at 13:54
2

I use the localrc.vim - Enable configuration file of each directory plugin for this. It not only allows sourcing of a "local .vimrc" file, but also offers filetype-specific settings for particular subdirectories (by default, the files are named .local.{filetype}.vimrc).

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324