Sean schrieb:
> (I found the whole thread was removed when my intention was to modify
> my reply, by "removing" and "posting" again ... Now, I tried to
> recover some based on my Vim buffer)
>
> Wow, Tony, you can come up a working function without being tested!
>
> Quick test showed both worked:
>
> ExpandPattern('\a') =
> 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
> ExpandPattern('\l') = 'abcdefghijklmnopqrstuvwxyz'
>
> The correct syntax to get String 'abcdefghijklmnopqrstuvwxyz' is:
> join(map(range(char2nr('a'),char2nr('z')),'nr2char(v:val)'),'')
>
> Thanks to Tony and Ag for inspiration!
>
> Sean
>
>
> PS: Tony's function
>
> function ExpandPattern(pattern)
> let res = ""
> let i = 0
> while i < 256
> let x = nr2char(i)
> if x =~ a:pattern
> let res .= x
> endif
> let i += 1
> endwhile
> return res
> endfunction
I wonder if there is a builtin way to echo control chars
strtrans()ed and in color at the same time ...
Usage: e.g.
:Cclass \l
:Cclass .
com! -nargs=1 Cclass call EchoTrans(CclassStr(<q-args>))
func! EchoTrans(str)
let len = strlen(a:str)
let pos = 0
echo ""
while pos < len
let print = matchstr(a:str, '^\p*', pos)
echon print
let pos += strlen(print)
if pos >= len
break
endif
let nonprint = matchstr(a:str, '^\%(\...@!.\)*', pos)
echohl SpecialKey
echon strtrans(nonprint)
echohl None
let pos += strlen(nonprint)
endwhile
endfunc
" ExpandPattern(pattern)
func! CclassStr(onecharpat)
return join(CclassList(a:onecharpat), "")
endfunc
func! CclassList(onecharpat)
" onecharpat - pattern to match a single char
let pat = '"'. escape(a:onecharpat, '\"'). '"'
return filter(map(range(0,255),'nr2char(v:val)'),'v:val=~'.pat)
endfunc
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---