Ⅰ. 插件描述
Incrementor Objects for VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'dahu/nexus'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'dahu/nexus'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'dahu/nexus'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/dahu/nexus
Ⅳ. 文档说明
Nexus
Generators for Vim
TIP: If you like Nexus and want to share the W00t!, I'm grateful for
https://www.gittip.com/bairuidahu/[tips] or
http://of-vim-and-vigor.blogspot.com/[beverages].
:List
The simplest way to use Nexus is through the ++:List++ command.
Visually select a range of lines and type ++:List++ to have
them numbered from 1 with leading 0 padding where appropriate.
TIP: If you want to change the default behaviour, ++:List++ accepts
the same arguments as ++:Nexus++ below.
:Nexus++:List++ adds numbers to the start of every line in the provided
- If you need to number elements within a line then you need to
- ++:Nexus++ instead.
The ++:Nexus++ command generates a callback function called Nexus()
which can be used in code or substitutions to yield the next value in
the associated series.
Examples
^^^^^^^^
.No arguments:
:Nexus
Will create a simple numeric sequence starting at 0 and incrementing
by 1 with each call to Nexus(). To replace all ++'foo'++ in your file
with this series you could then use:
:%s/foo/=Nexus()/g
.Nexus initialisation and substitute as a single command sequence:
:Nexus 10 1 %d, | %s/^(d*,)?/=Nexus()/
NOTE: The above command renumbers lines in the file starting from a
count of 10, incrementing by 1 each line, replacing existing numbers
if present. It uses a format of ``%d,'' to separate the new number
from the rest of the line text with a comma.
.Start and Step arguments
Numeric arguments will be parsed as follows:
:Nexus [step]
:Nexus start step
So:
:Nexus 2 " yields a counter starting at 0 with a step of 2: 0, 2, 4
:Nexus 3 2 " yields a counter starting at 3 with a step of 2: 3, 5, 7,
.Generator
A function name will change the generator used in the Nexus() callback
accordingly:
:Nexus nexus#fibonacci
or, if you've written your own generator for, say, prime numbers:
:Nexus Primes
.Format Function
An argument that contains a : or % will be taken as the format string.
The default format string is: '%d' which simply expands to the
(numeric!) value of the next item in the series at each call. If your
generator yields non-numeric values (such as the built-in nexus#alpha)
then you will need to create your own format string accordingly:
:Nexus %s nexus#alpha
NOTE: There are two spaces after the ++++ -- the first is captured as
part of the format string and the second separates the two arguments
(format string and generator).
These arguments may appear in any order with the caveat that the
++step++ or ++start++ and ++step++ will always be considered in that
order when numbers appear anywhere as standalone arguments. So,
although the following layout is not recommended for reader-clarity,
it is nonetheless possible:
:Nexus 1 nexus#alpha %s 2
and will create an alpha series starting at the first term and step by
two with each call to Nexus(). This will generate: b, d, f, h, j, ...
NOTE: Nexus generators are zero indexed. The zeroth alpha term is 'a'.
Series() Generator for Creating Incrementor Objects
Nexus comes with a incrementor-object generator called Series(), the objects of
which have a method called +next()+ which returns the next number in the
series. Create objects like this:
:let even_seq = Series(2)
The command:
:echo even_seq.next()
will print 0 on the first call, then 2, then 4, 6, 8, etc, on subsequent calls.
The Series constructor has the following signatures:
* +Series()+ -> 0, 1, 2, ...
* +Series(7)+ -> 0, 7, 14, 21, ...
* +Series(7, 2)+ -> 7, 9, 11, ...
* +Series(2, 7)+ -> 2, 9, 16, ...
* +Series('nexus#alpha')+ -> 'a', 'b', 'c', ...
* +Series('(%d) ')+ -> (0)
Nexus's Series Objects provide the following methods:
* +reset()+ to set the object back to its original values when created
* +next()+ to increment and return the next number in the series
* +value()+ to return the current value without incrementing internal state
Other Generators
^^^^^^^^^^^^^^^^
Other generators can be written for Nexus and passed to +Series()+ as
a string in the first argument:
:let fib = Series('Fibonacci')
Will create a Series object called +fib+ that generates the Fibonacci
sequence on each subsequent +.next()+ call. This generator and object
exist by default in the Nexus plugin. They are not expected to be
useful in themselves but rather serve to demonstrate how user-created
generators can be used with Nexus. Consult the code in
+plugin/nexus.vim+ to learn how to craft your generator. If you _do_
find a use for the Fibonacci sequence in your Vim life, I would love
to hear about it. :-)
Nexus also provides the following generators:
* ++nexus#alpha++ -- a, b, c, ..., z, aa, ab, ac, ...