Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting Vim to autoload files in ftdetect custom plugin project

Tags:

vim

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?

like image 970
user3139545 Avatar asked Dec 24 '22 13:12

user3139545


2 Answers

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.

like image 108
Samar Avatar answered May 14 '23 19:05

Samar


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
like image 27
zarak Avatar answered May 14 '23 20:05

zarak