Making Filetype-Specific Changes

We now have our filetype ready to go. Run the OpenMPC function again:

 
:​call​ OpenMPC()

And now for a handy trick: when we call the :set command on an option and include the ? flag instead of a value, :set echoes the option’s current value. Try this now with filetype:

 
:​set​ ​filetype​?

You should see Vim report our filetype:

 
filetype​=mpdv

With a filetype, we now can set buffer-specific options, using a file in that other filetype-related directory: ftplugin. Create that directory if it doesn’t exist yet.

Within ftplugin, create the file mpdv.vim. We won’t be doing too much in this file just yet—for now, just give it this line:

filetype/mpc/ftplugin/mpdv.vim
 
set​ ​buftype​=nofile

The buftype

Get The VimL Primer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.