/usr/share/vim/vim91/doc
NameSizeModeActions
arabic.txt122040644editdlrm
autocmd.txt778720644editdlrm
builtin.txt4320010644editdlrm
change.txt807140644editdlrm
channel.txt591030644editdlrm
cmdline.txt531810644editdlrm
debug.txt68960644editdlrm
debugger.txt54430644editdlrm
develop.txt231180644editdlrm
diff.txt183410644editdlrm
digraph.txt624430644editdlrm
editing.txt774990644editdlrm
eval.txt1732320644editdlrm
farsi.txt5230644editdlrm
filetype.txt306220644editdlrm
fold.txt247300644editdlrm
ft_ada.txt182120644editdlrm
ft_context.txt51610644editdlrm
ft_mp.txt47060644editdlrm
ft_ps1.txt21870644editdlrm
ft_raku.txt42190644editdlrm
ft_rust.txt198000644editdlrm
ft_sql.txt306940644editdlrm
gui.txt534990644editdlrm
gui_w32.txt191230644editdlrm
gui_x11.txt293180644editdlrm
hangulin.txt5980644editdlrm
hebrew.txt56660644editdlrm
help.txt94910644editdlrm
help.txt.vim-tiny13500644editdlrm
helphelp.txt160600644editdlrm
howto.txt29160644editdlrm
if_cscop.txt193250644editdlrm
if_lua.txt185460644editdlrm
if_mzsch.txt119410644editdlrm
if_ole.txt71170644editdlrm
if_perl.txt114510644editdlrm
if_pyth.txt408200644editdlrm
if_ruby.txt85160644editdlrm
if_sniff.txt2710644editdlrm
if_tcl.txt229480644editdlrm
indent.txt436990644editdlrm
index.txt823730644editdlrm
insert.txt881240644editdlrm
intro.txt396230644editdlrm
map.txt811760644editdlrm
mbyte.txt586400644editdlrm
message.txt319310644editdlrm
mlang.txt81600644editdlrm
motion.txt543870644editdlrm
netbeans.txt379570644editdlrm
options.txt4194020644editdlrm
os_390.txt47410644editdlrm
os_amiga.txt54660644editdlrm
os_beos.txt2930644editdlrm
os_dos.txt154950644editdlrm
os_haiku.txt85430644editdlrm
os_mac.txt68560644editdlrm
os_mint.txt3910644editdlrm
os_msdos.txt5230644editdlrm
os_os2.txt2990644editdlrm
os_qnx.txt40710644editdlrm
os_risc.txt3280644editdlrm
os_unix.txt26070644editdlrm
os_vms.txt337430644editdlrm
os_win32.txt149120644editdlrm
pattern.txt636530644editdlrm
pi_getscript.txt210770644editdlrm
pi_gzip.txt15470644editdlrm
pi_logipat.txt41960644editdlrm
pi_netrw.txt1817350644editdlrm
pi_paren.txt22740644editdlrm
pi_spec.txt41270644editdlrm
pi_tar.txt71910644editdlrm
pi_vimball.txt118590644editdlrm
pi_zip.txt77780644editdlrm
popup.txt403820644editdlrm
print.txt314450644editdlrm
quickfix.txt857010644editdlrm
quickref.txt730610644editdlrm
quotes.txt127480644editdlrm
README.Debian3240644editdlrm
recover.txt107270644editdlrm
remote.txt86260644editdlrm
repeat.txt465020644editdlrm
rileft.txt50630644editdlrm
russian.txt30240644editdlrm
scroll.txt143560644editdlrm
sign.txt268600644editdlrm
spell.txt642050644editdlrm
sponsor.txt67760644editdlrm
starting.txt745400644editdlrm
syntax.txt2375970644editdlrm
tabpage.txt172460644editdlrm
tags3910910644editdlrm
tags.vim-tiny19350644editdlrm
tagsrch.txt404750644editdlrm
term.txt556850644editdlrm
terminal.txt631690644editdlrm
testing.txt225070644editdlrm
textprop.txt204780644editdlrm
tips.txt213360644editdlrm
todo.txt3163580644editdlrm
uganda.txt130520644editdlrm
undo.txt178110644editdlrm
userfunc.txt206240644editdlrm
usr_01.txt70760644editdlrm
usr_02.txt242280644editdlrm
usr_03.txt239340644editdlrm
usr_04.txt191310644editdlrm
usr_05.txt279460644editdlrm
usr_06.txt106390644editdlrm
usr_07.txt159950644editdlrm
usr_08.txt193790644editdlrm
usr_09.txt115020644editdlrm
usr_10.txt292000644editdlrm
usr_11.txt130250644editdlrm
usr_12.txt134330644editdlrm
usr_20.txt137330644editdlrm
usr_21.txt184560644editdlrm
usr_22.txt149040644editdlrm
usr_23.txt127440644editdlrm
usr_24.txt208270644editdlrm
usr_25.txt191760644editdlrm
usr_26.txt82590644editdlrm
usr_27.txt177090644editdlrm
usr_28.txt160200644editdlrm
usr_29.txt202590644editdlrm
usr_30.txt226580644editdlrm
usr_31.txt103990644editdlrm
usr_32.txt53780644editdlrm
usr_40.txt235540644editdlrm
usr_41.txt652720644editdlrm
usr_42.txt138530644editdlrm
usr_43.txt74090644editdlrm
usr_44.txt289480644editdlrm
usr_45.txt176800644editdlrm
usr_50.txt45540644editdlrm
usr_51.txt255170644editdlrm
usr_52.txt134980644editdlrm
usr_90.txt167780644editdlrm
usr_toc.txt98860644editdlrm
various.txt324320644editdlrm
version4.txt139110644editdlrm
version5.txt3085290644editdlrm
version6.txt5769420644editdlrm
version7.txt6746980644editdlrm
version8.txt15998520644editdlrm
version9.txt16113250644editdlrm
vim9.txt917530644editdlrm
vim9class.txt410400644editdlrm
visual.txt226250644editdlrm
vi_diff.txt574040644editdlrm
windows.txt587060644editdlrm
workshop.txt3710644editdlrm
Edit: /usr/share/vim/vim91/doc/usr_51.txt (25517B)
*usr_51.txt* For Vim version 9.1. Last change: 2022 Jun 03 VIM USER MANUAL - by Bram Moolenaar Write plugins Plugins can be used to define settings for a specific type of file, syntax highlighting and many other things. This chapter explains how to write the most common Vim plugins. |51.1| Writing a generic plugin |51.2| Writing a filetype plugin |51.3| Writing a compiler plugin |51.4| Distributing Vim scripts Next chapter: |usr_52.txt| Write large plugins Previous chapter: |usr_50.txt| Advanced Vim script writing Table of contents: |usr_toc.txt| ============================================================================== *51.1* Writing a generic plugin *write-plugin* You can write a Vim script in such a way that many people can use it. This is called a plugin. Vim users can drop your script in their plugin directory and use its features right away |add-plugin|. There are actually two types of plugins: global plugins: For all types of files. filetype plugins: Only for files of a specific type. In this section the first type is explained. Most items are also relevant for writing filetype plugins. The specifics for filetype plugins are in the next section |write-filetype-plugin|. We will use |Vim9| syntax here, the recommended way to write new plugins. Make sure the file starts with the `vim9script` command. NAME First of all you must choose a name for your plugin. The features provided by the plugin should be clear from its name. And it should be unlikely that someone else writes a plugin with the same name but which does something different. A script that corrects typing mistakes could be called "typecorrect.vim". We will use it here as an example. For the plugin to work for everybody, it should follow a few guidelines. This will be explained step-by-step. The complete example plugin is at the end. BODY Let's start with the body of the plugin, the lines that do the actual work: > 12 iabbrev teh the 13 iabbrev otehr other 14 iabbrev wnat want 15 iabbrev synchronisation 16 \ synchronization The actual list should be much longer, of course. The line numbers have only been added to explain a few things, don't put them in your plugin file! FIRST LINE > 1 vim9script noclear You need to use `vim9script` as the very first command. Best is to put it in the very first line. The script we are writing will have a `finish` command to bail out when it is loaded a second time. To avoid that the items defined in the script are lost the "noclear" argument is used. More info about this at |vim9-reload|. HEADER You will probably add new corrections to the plugin and soon have several versions lying around. And when distributing this file, people will want to know who wrote this wonderful plugin and where they can send remarks. Therefore, put a header at the top of your plugin: > 2 # Vim global plugin for correcting typing mistakes 3 # Last Change: 2021 Dec 30 4 # Maintainer: Bram Moolenaar About copyright and licensing: Since plugins are very useful and it's hardly worth restricting their distribution, please consider making your plugin either public domain or use the Vim |license|. A short note about this near the top of the plugin should be sufficient. Example: > 5 # License: This file is placed in the public domain. NOT LOADING It is possible that a user doesn't always want to load this plugin. Or the system administrator has dropped it in the system-wide plugin directory, but a user has their own plugin they want to use. Then the user must have a chance to disable loading this specific plugin. These lines will make it possible: > 7 if exists("g:loaded_typecorrect") 8 finish 9 endif 10 g:loaded_typecorrect = 1 This also avoids that when the script is loaded twice it would pointlessly redefine functions and cause trouble for autocommands that are added twice. The name is recommended to start with "g:loaded_" and then the file name of the plugin, literally. The "g:" is prepended to make the variable global, so that other places can check whether its functionality is available. Without "g:" it would be local to the script. Using `finish` stops Vim from reading the rest of the file, it's much quicker than using if-endif around the whole file, since Vim would still need to parse the commands to find the `endif`. MAPPING Now let's make the plugin more interesting: We will add a mapping that adds a correction for the word under the cursor. We could just pick a key sequence for this mapping, but the user might already use it for something else. To allow the user to define which keys a mapping in a plugin uses, the item can be used: > 20 map a TypecorrAdd; The "TypecorrAdd;" thing will do the work, more about that further on. The user can set the "g:mapleader" variable to the key sequence that they want plugin mappings to start with. Thus if the user has done: > g:mapleader = "_" the mapping will define "_a". If the user didn't do this, the default value will be used, which is a backslash. Then a map for "\a" will be defined. Note that is used, this will cause an error message if the mapping already happened to exist. |:map-| But what if the user wants to define their own key sequence? We can allow that with this mechanism: > 19 if !hasmapto('TypecorrAdd;') 20 map a TypecorrAdd; 21 endif This checks if a mapping to "TypecorrAdd;" already exists, and only defines the mapping from "a" if it doesn't. The user then has a chance of putting this in their vimrc file: > map ,c TypecorrAdd; Then the mapped key sequence will be ",c" instead of "_a" or "\a". PIECES If a script gets longer, you often want to break up the work in pieces. You can use functions or mappings for this. But you don't want these functions and mappings to interfere with the ones from other scripts. For example, you could define a function Add(), but another script could try to define the same function. To avoid this, we define the function local to the script. Fortunately, in |Vim9| script this is the default. In a legacy script you would need to prefix the name with "s:". We will define a function that adds a new typing correction: > 28 def Add(from: string, correct: bool) 29 var to = input($"type the correction for {from}: ") 30 exe $":iabbrev {from} {to}" ... 34 enddef Now we can call the function Add() from within this script. If another script also defines Add(), it will be local to that script and can only be called from that script. There can also be a global g:Add() function, which is again another function. can be used with mappings. It generates a script ID, which identifies the current script. In our typing correction plugin we use it like this: > 22 noremap