Re: joining text in a veriable
- c928400@... wrote:
>You can also use "\<C-J>" (with the quotes!) instead of
> Thus wrote Devin Weaver (ktohg@...) on :
> > Is there a way in a function to join the text? Take axample:
> > function MyFunc( )
> > exec "normal! Vjjj\"xy"
> > let @x = join (@x)
> > endfunction
> > Or something simmular. substitute (@x, '\s*\n+\s*', ' ', 'g') would be fine but
> > I want to make this VIM 5.7 compatable.
> How about the following (make join() into Join() in your example):
> fun! Join(str)
> return substitute(a:str, nr2char(10), '', 'ge')
> Here I make use of knowledge of the string delimiter that vim uses.
> Unfortunately, this will kill ^@'s in the file...
> You could perhaps use
> function MyFunc( )
> exec "normal! Vjjj\"xy"
> exec 'norm! "xp4gJ"xdd'
> as this does not have the problem above (and you do not seem to mind
> meddling with :norm anyway)
nr2char(10). If you also want to remove leading and trailing spaces,
use "\\s*\<C-J>\\s*" (with the quotes) or '\s*'."\<C-J>".'\s*' or
HTH --Benji Fisher