sponsor Vim development Vim logo Vim Book Ad

foo.vim : examples of Vim functions (and a few commands, etc.)

 script karma  Rating 178/65, Downloaded by 18126    Comments, bugs, improvements  Vim wiki

created by
Benji Fisher
script type
This file is a collection of Vim functions I have written, many of them in
response to questions posted on the vim users' list.  They are all reasonably
short, so I hope they will be good examples if you are trying to learn how to
write your own Vim functions.  You may even find some of the functions
useful, such as the :Range command and the Mark(), Common(), Count(),
GetModelines(), VarTab(), and SmartBS() functions.
install details

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
foo.vim 2.1.1 2005-11-30 6.0 Benji Fisher improved "text object" :vmap's for i", i', a", a' (will be obsolete in vim 7) and some tweaks to the comments
foo.vim 2.1 2004-01-12 6.0 Benji Fisher New functions:

GCD():  an example of recursion
RepeatString():  Generate "ababababababababab"
InvertString():  by Preben "Peppe" Guldberg
MyMarks():  save file positions to a file and read them
FooSID():  expose the script ID so you can call script-local functions
foo.vim 2.0.3 2003-06-27 6.0 Benji Fisher I changed :map to :imap for the VarTab() function.
foo.vim 2.0.2 2003-06-11 6.0 Benji Fisher Oops, I uploaded the wrong file!
matchit.vim 2.0.2 2003-06-11 6.0 Benji Fisher improvements to the EditFun command and function
foo.vim 2.0.1 2002-11-19 6.0 Benji Fisher Oops:  make sure script variables are defined before used.
foo.vim 2.0 2002-11-15 6.0 Benji Fisher I added a user configuration section, as discussed on the vim-dev
mailing list.  With the defaults, most :imap's are not defined, so it
is safer to include this in your plugin directory, if you like using any
of the commands or functions it defines.  Like the rest of the file,
the configuration section is meant as an example to be followed.
The user should copy this section to a separate file, foo.vimrc .

I also added functions to save script-local variables in the script
file, so they are made persistent.
foo.vim 1.4 2002-08-06 5.7 Benji Fisher Just a format change:  This version has unix-style line endings, and I
updated the modelines to keep it that way.
foo.vim 1.4 2002-08-04 5.7 Benji Fisher I added Common(str1, str2), which returns the initial matching part (if any)
of two input strings.
I also added TWIN() (The Weather Is Nice):  an example of how to prompt
the user for input and add some text based on that input.
foo.vim 1.3 2002-03-31 5.7 Benji Fisher I added the :Iabbr command, which allows you to define abbreviations like

:Iabbr foo foo()<Left>

that can be triggered by a space without inserting that space.  Several contributors to the vim users' list suggested improvements to this command.
foo.vim 1.2 2001-12-06 5.7 Benji Fisher I added a table of contents, with a one-line description of the purpose
and a one-line description of the techniques used by each example.
I also trimmed a few of the less interesting examples and made a
couple of corrections, added a few comments, etc.
foo.vim 1.1 2001-11-22 6.0 Benji Fisher I improved the GetModelines() function.
Maybe something else is new, too...
foo.vim 1.0 2001-08-28 5.7 Benji Fisher Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo