Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write a vimrc file that (automatically) applies only to a specific folder

Tags:

vim

say that i have a project which lies in a folder called 'bin', and i want some specific vim configuration automatically loaded when i edit any file inside the project folder. how can i do that?

like image 889
freenight Avatar asked Apr 02 '10 01:04

freenight


People also ask

Where should your vimrc file be?

The user vimrc file often does not exist until created by the user. If you cannot find $HOME/. vimrc (or $HOME/_vimrc on Windows) then you can, and probably should, just create it. The system vimrc should normally be left unmodified and is located in the $VIM * directory.

What type of file is vimrc?

A VIMRC file is a settings file used by the Vim text editor.

How do I create a .vimrc file in Windows?

To source vimrc in all buffers in the current window I do :bufdo so~/. vimrc ,to source vimrc in the ACTIVE buffers in all windows I do :windo so~/. vimrc .


1 Answers

I think what you want is an autocommand. Perhaps something like this:

autocmd BufRead,BufNewFile ~/bin/* call SetBinOptions()

function SetBinOptions() {
    setlocal number
    setlocal nowrap
    ...
}

If you need to do something complex with the path matching, you can take a slightly different approach, making the decision about whether to apply the options within the function. Suppose you had some regex the path had to match:

autocmd BufRead,BufNewFile * call SetCustomOptions()

function SetCustomOptions() {
    if (match(expand("%:p"), /regex/) {
        setlocal number
        setlocal nowrap
        ...
    }
}
like image 58
Cascabel Avatar answered Oct 20 '22 22:10

Cascabel