How can I determine if a filetype plugin (such as vim-latexsuite) has been installed and activated when I open the appropriate file? Another popular editor would indicate that the relevant "minor mode" is active. What's the vim equivalent?


How can I determine if a filetype plugin (such as vim-latexsuite) has been installed

You could use :scriptnames which list all sourced files.

Another option is to check for the variable indicating if the plugin was loaded, as it is recommended practice to allow the user to disable the loading of a given plugin.. You usually can find g:loaded_... variable inside the <plugin_name>/plugin folder. For the plugin you mentioned you could use echo exists("loaded_libList").

and activated when I open the appropriate file?

If it is a filetype plugin it should be activated automatically when the 'filetype' option is set. You can check if the option is correct for the current buffer:

:set filetype?

Another popular editor would indicate that the relevant "minor mode" is active. What's the vim equivalent?

You could customize your statusline to show such indication, either using plugins or directly through options, as explained in :help 'statusline' and at vi-improved.org.

| improve this answer | |

Vim plugins don't come with any activation indication, and in a proper setup, this isn't necessary.

You can quickly check whether a plugin is active by querying for its side effects, typically mappings. So, for example, I know that NERDCommenter mappings start with <Leader>c, so a query for its activation would be :nmap <Leader>c. If the mappings are listed, the plugin is active. The same can be achieved for custom commands and :autocmd in the plugin's group. Most plugins also define an inclusion guard variable g:loaded_pluginname that can be checked.

The same applies to filetype plugins (and the effects should then all be buffer-scoped). The most important factor in determining the active plugins is the correct detection of the filetype. You can query that via :setlocal filetype?, or even put this into your 'statusline' via the %y / %Y item.

| improve this answer | |

In that particular case, I'd only play with :scriptnames. We can't expect to use a global variable to check whether a ftplugin has been loaded -- LaTeXSuite may have plugins, I don't remember, what is certain is that is has plenty ftplugin scripts. Many ftplugins use b:did_ftplugin (the ones shipped with Vim at least), but this approach definitely does not scale: in consequence, not all ftplugins use this pointless variable, and we can't check for a generic variable name to know whether a given ftplugin has been loaded -- for instance, for C alone I have 22 ftplugins, they're definitively not using the same anti-reinclusion guard.

So :scriptname. Alas :scriptname gives a lot of unordered results, for our human eyes. Fortunately execute() (a very recent function), and filter() come to the rescue. In that case, I would look for latex related vim scripts with

:echo filter(split(execute(':scriptname'), "\n"), 'v:val =~? "tex"') 
" or even "latex" instead of "tex"

Also if you're using a plugin manager, it's likely that the plugin manager is using 'runtimepath' option. You can display its value with :echo &rtp. You may even filter its value with:

:echo filter(split(&rtp), ','), 'v:val =~? "tex")

(This will tell you whether your plugin manager has activated your plugin, LaTeX-suite in your case. This won't tell you whether the related ftplugins have correctly been loaded. :scriptname will give you this information.)

| improve this answer | |

One way is to do a regex search on runtimepath:

if match(&runtimepath, 'MY-PLUGIN') != -1
    " ...

If you're using vim-plug, here's a general purpose method to check:

function! PlugLoaded(name)
    return (
        \ has_key(g:plugs, a:name) &&
        \ isdirectory(g:plugs[a:name].dir) &&
        \ stridx(&rtp, g:plugs[a:name].dir) >= 0)


if PlugLoaded('MY-PLUGIN')
    " ...
| improve this answer | |
  • It's not enough. Also, it only takes care of plugins installed with plugin managers. In all cases, it doesn't take care of ftplugin scripts shipped within plugins, which was OP' question. – Luc Hermitte Nov 9 '17 at 13:11

If you activate filetype plugins by autocommands, you may set the verbose=9 so that Vim echo the autocommands as it executes them:

:set verbose=9
| improve this answer | |

If you use vim-plug, it sets a variable called plugs which lists all your loaded plugins, and some information about them. I solved your question for myself when I needed to check whether I was running YCM or coc.nvim. You can see if a plugin is loaded by running has_key(plugs, "name"), for example:

if has_key(plugs, 'YouCompleteMe')
        call YCM()
if has_key(plugs, "coc.nvim")
        call CocStart()

Note: this only shows if it's currently listed in your vimrc, and not, for example, if you have it set to lazy load, so

    Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'}
if has_key(plugs, 'nerdtree')
        echo "HAS NERDTREE"

will still print that at startup, even though nerdtree hasn't been loaded yet.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.