Ⅰ. 插件描述
vim utility to expand by pattern looks like "{add,remove}Item{0..3}"Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'zsaberlv0/zfvimexpand'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'zsaberlv0/zfvimexpand'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'zsaberlv0/zfvimexpand'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/zsaberlv0/zfvimexpand
Ⅳ. 文档说明
# ZFVimExpand
expand utility
if you like my work, check here for a list of my vim plugins
before expand:
void {add,remove}Item{0..2}(int item{..}) { }after expand: (by
:ZFExpandReversely)void addItem0(int item0) { } void removeItem0(int item0) { } void addItem1(int item1) { } void removeItem1(int item1) { } void addItem2(int item2) { } void removeItem2(int item2) { }
inspired from Olical/vim-expand, with these advantages:
- implemented in pure vim script, support Windows
- more configurable
- more pattern expand rule
- able to add your own rules
disadvantages:
- no shell env support (such as
$HOME)
How to use
use Vundle or any other plugin manager is recommended
Plugin 'ZSaberLv0/ZFVimExpand'- use
:ZFExpand, in normal mode (expand current line) or visual mode (selected lines)
pattern rules:
{2..5}: expand to2 3 4 5number sequence{a..d}: expand toa b c dletter sequence{\xAB12..\xAB21}: expand to string sequence accorrding to the HEX value,
these token are equivalent:\x\X\u\U{aa,bb,cc}: expand toaa bb ccstring sequence{..}: repeat previous pattern{..3}: repeat 3rd pattern (index start from 0)
you may also supply your own pattern rules, see the Config below
Config
" the default pattern tags
let g:ZFVimExpand_tagL='{'
let g:ZFVimExpand_tagR='}'
" token to split text
let g:ZFVimExpand_textSplitToken=','
" token to split range
let g:ZFVimExpand_rangeSplitToken='..'
" token to repeat previous pattern
let g:ZFVimExpand_repeatToken='..'
" whether auto reindent after expand
let g:ZFVimExpand_reindent=0
" add your custom item parse rules
" return passed list if success, or empty list or string if unable to parse
"
" for example
" {add|remove}User
" your parser would receive this as pattern
" add|remove
let g:ZFVimExpand_customItemParser='MyItemParser'
function! MyItemParser(pattern)
return split(a:pattern, '|')
endfunctionFunctions
:ZFExpand [tagL, tagR]tagLandtagRare optional, it's useful if your content contains the tag token, example:int n<0..2> = {0,1,2};
`:ZFExpand < >` would result:
int n0 = {0,1,2};
int n1 = {0,1,2};
int n2 = {0,1,2};:ZFExpandReversely [tagL, tagR]same as
:ZFExpandbut expand items in reverse order