Tuesday, May 8, 2012

Re: Expanding a range of characters

if buffer is empty, setline is useful.

call setline('.', call('range', split('46-58', '-')))

On Tuesday, May 8, 2012 2:25:34 PM UTC+9, JohnBeckett wrote:
> The following might be slightly better (and this handles '@-@',
> but I still haven't read all the docs to see if there is
> anything else needed; testing needed!):
>
> function! ShowChars(spec)
> let result = []
> for item in split(a:spec, ',')
> if len(item) > 1
> if item == '@-@'
> call add(result, char2nr(item))
> else
> call extend(result, call('range', split(item, '-')))
> endif
> else
> if item == '@' " assume this is [A-Za-z]
> for [c1, c2] in [['A', 'Z'], ['a', 'z']]
> call extend(result, range(char2nr(c1), char2nr(c2)))
> endfor
> else
> call add(result, char2nr(item))
> endif
> endif
> endfor
> return join(map(result, 'nr2char(v:val)'), ', ')
> endfunction
>
> John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: