user3139545
user3139545

Reputation: 7374

Not getting Vim to autoload files in ftdetect custom plugin project

The example I am following is from the book The VimL Primer Chap 4.

In the ftdetect dir I have the following line:

autocmd BufRead,BufNewFile *.mpdv set filetype=mpdv

In a file called mpdv.vim

However this command is not executed when I open a mpdv file. In .vimrc I have:

filetype plugin on

The way im loading the plugin is the following: In ~/.vimrc I have:

set exrc

This forces vim to load local .vimrc files

Then in my projects pluginfolder i have the follwoing .vimrc

set runtimepath+=path/to/my/plugin

What can I do the debug why vim is not loading my autocmd when I open a mpdv file?

Upvotes: 6

Views: 1880

Answers (3)

Samar
Samar

Reputation: 1955

One thing I've noticed (and which seems to be the deal with your case as well) is that if you add new path on runtimepath, you should have the filetype plugin on done after updating the runtimepath.

For example, with the following vimrc, it would work fine:

set runtimepath+=/home/techgaun/fun/vim/mpc
filetype plugin indent on

And, if you run :scriptnames, you should see the ftdetect script loaded fine from your mpc plugin directory.

Upvotes: 8

Razzi Abuissa
Razzi Abuissa

Reputation: 4112

If you're using vim's native :packadd functionality, note the following from :h packadd:

            If the filetype detection was not enabled yet (this
            is usually done with a `syntax enable` or `filetype on`
            command in your .vimrc file), this will also look
            for "{name}/ftdetect/*.vim" files.

So be sure to put any packadd calls before either syntax enable or filetype plugin indent on:

packadd! UltiSnips
" etc

filetype plugin indent on

This is similar to enabling filetype after manually modifying runtimepath.

Upvotes: 1

zarak
zarak

Reputation: 3003

In my case, vim appeared to not be sourcing the files under the ftdetect and ftplugin directories in the custom runtimepath. I tried putting the directories under my .vim folder:

.vim
├── autoload
│   └── mpc.vim
├── ftdetect
│   └── mpdv.vim
├── ftplugin
│   └── mpdv.vim
└── plugin
    └── mpc.vim

Now the script under ftdetect runs, as can be seen when I run :scriptnames:

1: /usr/share/vim/vimrc                                                                             
2: /usr/share/vim/vim74/debian.vim
3: ~/.vimrc
4: /usr/share/vim/vim74/filetype.vim
5: ~/.vim/ftdetect/mpdv.vim
6: /usr/share/vim/vim74/ftplugin.vim
7: /usr/share/vim/vim74/syntax/syntax.vim
8: /usr/share/vim/vim74/syntax/synload.vim
9: /usr/share/vim/vim74/syntax/syncolor.vim
10: ~/.vim/plugin/mpc.vim

Upvotes: 4

Related Questions