!exists("*s:Func")
: function s:Func(arg)
: ...
: endfunction
:endif
<
UNDO *undo_indent* *undo_ftplugin*
When the user does ":setfiletype xyz" the effect of the previous filetype
should be undone. Set the b:undo_ftplugin variable to the commands that will
undo the settings in your filetype plugin. Example: >
let b:undo_ftplugin = "setlocal fo< com< tw< commentstring<"
\ .. "| unlet b:match_ignorecase b:match_words b:match_skip"
Using ":setlocal" with "<" after the option name resets the option to its
global value. That is mostly the best way to reset the option value.
This does require removing the "C" flag from 'cpoptions' to allow line
continuation, as mentioned above |use-cpo-save|.
For undoing the effect of an indent script, the b:undo_indent variable should
be set accordingly.
FILE NAME
The filetype must be included in the file name |ftplugin-name|. Use one of
these three forms:
.../ftplugin/stuff.vim
.../ftplugin/stuff_foo.vim
.../ftplugin/stuff/bar.vim
"stuff" is the filetype, "foo" and "bar" are arbitrary names.
SUMMARY *ftplugin-special*
Summary of special things to use in a filetype plugin:
<LocalLeader> Value of "maplocalleader", which the user defines as
the keys that filetype plugin mappings start with.
:map <buffer> Define a mapping local to the buffer.
:noremap <script> Only remap mappings defined in this script that start
with <SID>.
:setlocal Set an option for the current buffer only.
:command -buffer Define a user command local to the buffer.
exists("*s:Func") Check if a function was already defined.
Also see |plugin-special|, the special things used for all plugins.
==============================================================================
*41.13* Writing a compiler plugin *write-compiler-plugin*
A compiler plugin sets options for use with a specific compiler. The user can
load it with the |:compiler| command. The main use is to set the
'errorformat' and 'makeprg' options.
Easiest is to have a look at examples. This command will edit all the default
compiler plugins: >
:next $VIMRUNTIME/compiler/*.vim
Use |:next| to go to the next plugin file.
There are two special items about these files. First is a mechanism to allow
a user to overrule or add to the default file. The default files start with: >
:if exists("current_compiler")
: finish
:endif
:let current_compiler = "mine"
When you write a compiler file and put it in your personal runtime directory
(e.g., ~/.config/nvim/compiler for Unix), you set the "current_compiler"
variable to make the default file skip the settings.
*:CompilerSet*
The second mechanism is to use ":set" for ":compiler!" and ":setlocal" for
":compiler". Vim defines the ":CompilerSet" user command for this. This is
an example: >
CompilerSet errorformat& " use the default 'errorformat'
CompilerSet makeprg=nmake
When you write a compiler plugin for the Vim distribution or for a system-wide
runtime directory, use the mechanism mentioned above. When
"current_compiler" was already set by a user plugin nothing will be done.
When you write a compiler plugin to overrule settings from a default plugin,
don't check "current_compiler". This plugin is supposed to be loaded
last, thus it should be in a directory at the end of 'runtimepath'. For Unix
that could be ~/.config/nvim/after/compiler.
==============================================================================
*41.14* Writing a plugin that loads quickly *write-plugin-quickload*
A plugin may grow and become quite long. The startup delay may become
noticeable, while you hardly ever use the plugin. Then it's time for a
quickload plugin.
The basic idea is that the plugin is loaded twice. The first time user
commands and mappings are defined that offer the functionality. The second
time the functions that implement the functionality are defined.
It may sound surprising that quickload means loading a script twice. What we
mean is that