===================备用===================
fun! MatchSign()
let startsign={1:'{'}
let startsign[2]='['
let startsign[3]='('
let outstring=''
exec ':redir =>> outstring'
exec ':echo startsign'
exec ':redir END'
let typename=string(type(outstring))
let info=
\[
\"\"==========================================================================",
\"\"redir =>> outstring开始将命令输出定向到变量outstring",
\"\":echo startsign 将dict字典变量startsign重定向到变量outstring",
\"\"redir END重定向结束",
\"\"typename==".typename.":说明说明outstring重定向后依然是string类型的变量",
\"\":h type()可以看到返回值1,对应的类型是: 1 v:t_string",
\"\"let execString = 'call append(line('$'),info)'",
\"\"call eval(execString)",
\"\"eval()把string当命令来执行",
\"\":下行是outstring:",
\"\"".substitute(string(outstring),'\n','','g'),
\"\"substitute()出命令行输出产生的换行符^@",
\"\"call append(line('$'),info)将info字符串写入到当前文件尾部",
\"\"line('$')返回末行号",
\"\"call MatchSign()的作用是当用户:so %时,MatchSign()函数被调用",
\"\"=========================================================================="
\]
let execString = "append(line('$'),info)"
call eval(execString)
echo iconv("删除前的startsign为:".string(startsign).",remove(startsign,'3')删除列表3后返回的:",&fileencoding,&encoding)
echo string(remove(startsign,'3'))
echo iconv("是被remove()删除字典键'3'所对应的值",&fileencoding,&encoding)
echo string(startsign)
endf
call MatchSign()
运行后
fun! MatchSign()
let startsign={1:'{'}
let startsign[2]='['
let startsign[3]='('
let outstring=''
exec ':redir =>> outstring'
exec ':echo startsign'
exec ':redir END'
let typename=string(type(outstring))
let info=
\[
\"\"==========================================================================",
\"\"redir =>> outstring开始将命令输出定向到变量outstring",
\"\":echo startsign 将dict字典变量startsign重定向到变量outstring",
\"\"redir END重定向结束",
\"\"typename==".typename.":说明说明outstring重定向后依然是string类型的变量",
\"\":h type()可以看到返回值1,对应的类型是: 1 v:t_string",
\"\"let execString = 'call append(line('$'),info)'",
\"\"call eval(execString)",
\"\"eval()把string当命令来执行",
\"\":下行是outstring:",
\"\"".substitute(string(outstring),'\n','','g'),
\"\"substitute()出命令行输出产生的换行符^@",
\"\"call append(line('$'),info)将info字符串写入到当前文件尾部",
\"\"line('$')返回末行号",
\"\"call MatchSign()的作用是当用户:so %时,MatchSign()函数被调用",
\"\"=========================================================================="
\]
let execString = "append(line('$'),info)"
call eval(execString)
echo iconv("删除前的startsign为:".string(startsign).",remove(startsign,'3')删除列表3后返回的:",&fileencoding,&encoding)
echo string(remove(startsign,'3'))
echo iconv("是被remove()删除字典键'3'所对应的值",&fileencoding,&encoding)
echo string(startsign)
endf
call MatchSign()
"==========================================================================
"redir =>> outstring开始将命令输出定向到变量outstring
":echo startsign 将dict字典变量startsign重定向到变量outstring
"redir END重定向结束
"typename==1:说明说明outstring重定向后依然是string类型的变量
":h type()可以看到返回值1,对应的类型是: 1 v:t_string
"let execString = 'call append(line('$'),info)'
"call eval(execString)
"eval()把string当命令来执行
":下行是outstring:
"'{''1'': ''{'', ''2'': ''['', ''3'': ''(''}'
"substitute()出命令行输出产生的换行符^@
"call append(line('$'),info)将info字符串写入到当前文件尾部
"line('$')返回末行号
"call MatchSign()的作用是当用户:so %时,MatchSign()函数被调用
"==========================================================================
截图:
我的QQ群:518607566,欢迎大家来一起讨论编程技术 我的微信:13841309382