Ⅰ. 插件描述
Library of functions to work with lists/arraysⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin '/liblist-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle '/liblist-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug '/liblist-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/vim-scripts/libList.vim
Ⅳ. 文档说明
libList.vim is a set of functions to work with lists or one level arrays.
Lists are strings variables with values separated by g:listSep character (comma by default). You may redefine g:listSep variable as you wish.
Here are available functions :
- AddListItem( array, newItem, index ) : Add item "newItem" to array "array" at "index" position
- GetListItem( array, index ) : Return item at "index" position in array "array"
- GetListMatchItem( array, pattern ) : Return item matching "pattern" in array "array"
- GetListCount( array ) : Return the number of items in array "array"
- RemoveListItem( array, index ) : Remove item at "index" position from array "array"
- ReplaceListItem( array, index, item ) : Remove item at "index" position by "item" in array "array"
- ExchangeListItems( array, item1Index, item2Index ) : Exchange item "item1Index" with item "item2Index" in array "array"
- QuickSortList( array, beg, end ) : Return array "array" with items between "beg" and "end" sorted
Example:
let mylist=""
echo GetListCount( mylist ) " --> 0
let mylist = AddListItem( mylist, "One", 0 ) " mylist == "One"
let mylist = AddListItem( mylist, "Three", 1 ) " mylist == "One,Three"
let mylist = AddListItem( mylist, "Two", 1 ) " mylist == "One,Two,Three"
echo GetListCount( mylist ) " --> 3
echo GetListItem( mylist, 2 ) " --> Three
echo GetListMatchItem( mylist, "w" ) " --> two
echo GetListMatchItem( mylist, "e" ) " --> One
let mylist = RemoveListItem( mylist, 2 ) " mylist == "One,Two"
echo GetListCount( mylist ) " --> 2
let mylist = ReplaceListItem( mylist, 0, "Three" ) " mylist == "Three,Two"
let mylist = ExchangeListItems( mylist, 0, 1 ) " mylist == "Two,Three"
let mylist = AddListItem( mylist, "One", 0 ) " mylist == "One,Two,Three"
let mylist = QuickSortList( mylist, 0, GetListCount(mylist)-1 ) " mylist == "One,Three,Two"