inkarkat / vim-ingo-library

Vimscript library of common functions
91 stars 7 forks source link

INGO-LIBRARY

by Ingo Karkat

DESCRIPTION

This library contains common autoload functions that are used by almost all of my plugins (http://www.vim.org/account/profile.php?user_id=9713). Instead of duplicating the functionality, or installing potentially conflicting versions with each plugin, this one core dependency fosters a lean Vim runtime and easier plugin updates.

Separating common functions is explicitly recommended by Vim; see write-library-script. The autoload mechanism was created to make this really easy and efficient. Only those scripts that contain functions that are actually used are loaded, the rest is ignored; it just "wastes" the space on disk. (Not using autoload functions, and duplicating utility functions in the plugin script itself, now that would be truly bad.)

Still, if you only use one or few of my plugins, yes, this might look wasteful. However, I have published an awful lot of plugins (most of which now use ingo-library), and intend to continue to do so. Considering that, the decision to extract the common functionality (which caused a lot of effort for me) benefits both users (no duplication, no incompatibilities, faster updates) and me (less overall effort in maintaining, more time for features). Please keep that in mind before complaining about this dependency.

Furthermore, several other authors have been following the same approach:

RELATED WORKS

Other authors have published separate support libraries, too:

There have been initiatives to gather and consolidate useful functions into a "standard Vim library", but these efforts have mostly fizzled out.

USAGE

This library is mainly intended to be used by my own plugins. However, I try
to maintain backwards compatibility as much as possible. Feel free to use the
library for your own plugins and customizations, too. I'd also like to hear
from you if you have additions or comments.

EXCEPTION HANDLING

For exceptional conditions (e.g. cannot locate window that should be there)
and programming errors (e.g. passing a wrong variable type to a library
function), error strings are |:throw|n. These are prefixed with (something
resembling) the short function name, so that it's possible to :catch these
and e.g. convert them into a proper error (e.g. via
ingo#err#SetCustomException()).

CONFIGURATION

The filespec to the external "date" command can be set via:

let g:IngoLibrary_DateCommand = 'date'

The preferred date format used by ingo#date#format#Preferred() can be set to a strftime() format via:

let g:IngoLibrary_PreferredDateFormat = '%x'

The size of the file cache (in bytes) used by ingo#file#GetLines() can be set via:

let g:IngoLibrary_FileCacheMaxSize = 1048576

The string used as a replacement for truncated text can be set via:

let g:IngoLibrary_TruncateEllipsis = "\u2026"

The check for special windows in ingo#window#special#IsSpecialWindow() can be customized via a List of Expressions or Funcrefs that are passed the window number, and which should return a boolean flag. If any predicate is true, the window is deemed special.

let g:IngoLibrary_SpecialWindowPredicates =
\   ['bufname(winbufnr(v:val)) =~# "^\\[\\%(Scratch\\|clipboard\\)\\]$"']

ingo#plugin#marks#Reserve() by default uses any unused mark. You can instead assign a fixed set of marks that will be available for plugins via:

let g:IngoLibrary_Marks = 'abcABC'

Some special filenames are caught by BufNewFile|,|BufRead autocmds and translated into existing files. ingo#cmdargs#glob#Resolve() can be taught those patterns by configuring a List of Funcrefs or expressions in g:IngoLibrary_SpecialFilePredicates that take a single filespec argument / v:val and return whether this is an existing file. This will then correct the statistics information returned by the function. By default, includes any filespec that starts with a "protocol:/" (e.g. scp:// for netrw), and also file:lnum[:column] special filenames if https://github.com/bogado/file-line is installed.

The ingo#text#InsertHere() function is often used to insert text at the cursor position by plugins that don't want to offer separate insert / append mappings (comparable to p|/|P pasting). The function tries to find a meaningful insertion point. Its strategy can be tweaked via the following values:

If you use some operator-pending mappings as hooks into default motions (e.g. : or /) that still maintain the original functionality, ingo#query#get#Motion() can be instructed to ignore those mappings and instead treat them as the built-in motions (i.e. still query the command-line or search pattern). Define those keys you want ignored as keys in a Dict (values don't matter):

let g:IngoLibrary_QueryMotionIgnoredMotions = {':': 1, '/': 1, '?': 1}

If you have custom operator-pending mappings that do some tricks like obtaining additional characters until they're done and moving the cursor, define those keys as keys, and an appendage pattern as value (or the empty String if there're no additional keys). The appendage patterns will capture additional keys until either the pattern does not match any longer (the motion then is deemed invalid and aborts), or until the first capture group is non-empty (the motion then is deemed complete).

let g:IngoLibrary_QueryMotionCustomMotions = {'key': 'patter\(n\)'}

Motions can be forced to be character- / line- / blockwise (forced-motion). If you have mapped alternatives for v / V / CTRL-V, define them as keys in:

let g:IngoLibrary_QueryMotionCustomMotionModifiers = {"\<C-q>": 1}

If you've remapped the c_CTRL-K trigger key for digraphs, you can adapt the digraph detection by ingo#query#get#CharOrDigraph() and ingo#query#get#[Valid]Char() to the changed mapping via:

let g:IngoLibrary_DigraphTriggerKey = "\<C-k>"

INSTALLATION

The code is hosted in a Git repo at https://github.com/inkarkat/vim-ingo-library You can use your favorite plugin manager, or "git clone" into a directory used for Vim packages. Releases are on the "stable" branch, the latest unstable development snapshot on "master".

This script is also packaged as a vimball. If you have the "gunzip" decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress the archive first, e.g. using WinZip. Inside Vim, install by sourcing the vimball or via the :UseVimball command.

vim ingo-library*.vmb.gz
:so %

To uninstall, use the :RmVimball command.

DEPENDENCIES

CONTRIBUTING

Report any bugs, send patches, or suggest features via the issue tracker at https://github.com/inkarkat/vim-ingo-library/issues or email (address below).

HISTORY

Note: Update version also in autoload/ingo/version.vim

1.046 RELEASEME
1.045 03-Oct-2024
1.044 08-Apr-2022
1.043 04-Feb-2022
1.042 03-Aug-2020
1.041 12-Mar-2020
1.040 31-Oct-2019
1.039 10-Sep-2019
1.038 09-Jun-2019
1.037 28-Mar-2019
1.036 17-Mar-2019
1.035 29-Sep-2018
1.034 13-Feb-2018
1.033 14-Dec-2017
1.032 20-Sep-2017
1.031 27-Jun-2017
1.030 26-May-2017
1.029 24-Jan-2017
1.028 30-Nov-2016
1.027 30-Sep-2016
1.026 11-Aug-2016
1.025 09-Aug-2016
1.024 23-Apr-2015
1.023 09-Feb-2015
1.022 26-Sep-2014
1.021 10-Jul-2014
1.020 11-Jun-2014
1.019 24-May-2014
1.018 14-Apr-2014
1.017 13-Mar-2014
1.016 22-Jan-2014
1.015 28-Nov-2013
1.014 14-Nov-2013
1.013 13-Sep-2013
1.012 05-Sep-2013
1.011 02-Aug-2013
1.010 09-Jul-2013
1.009 03-Jul-2013
1.008 13-Jun-2013
1.007 06-Jun-2013
1.006 29-May-2013
1.005 02-May-2013
1.004 10-Apr-2013
1.003 27-Mar-2013
1.002 08-Mar-2013
1.001 21-Feb-2013
1.000 12-Feb-2013
0.001 05-Jan-2009

Copyright: (C) 2009-2024 Ingo Karkat - Contains URL encoding / decoding algorithms written by Tim Pope. - The VIM LICENSE applies to this plugin.

Maintainer: Ingo Karkat <ingo@karkat.de>