Loading ...
Sorry, an error occurred while loading the content.

joining text in a veriable

Expand Messages
  • Devin Weaver
    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.
    Message 1 of 3 , Dec 6, 2000
    • 0 Attachment
      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.

      Thanks.

      --
      If VIM were a woman, I'd marry her. Slim, organized, helpful and beautiful;
      what's not to like?
    • c928400@student.dtu.dk
      ... How about the following (make join() into Join() in your example): fun! Join(str) return substitute(a:str, nr2char(10), , ge ) endfun Here I make use of
      Message 2 of 3 , Dec 6, 2000
      • 0 Attachment
        Thus wrote Devin Weaver (ktohg@...) on [001206]:
        > 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')
        endfun

        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'
        endfunction

        as this does not have the problem above (and you do not seem to mind
        meddling with :norm anyway)

        Peppe
        --
        "Before you criticize someone, walk
        Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
        c928400@... (o o) he gets angry, he'll be a mile away
        ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
      • Benji Fisher
        ... You can also use (with the quotes!) instead of nr2char(10). If you also want to remove leading and trailing spaces, use s* s* (with
        Message 3 of 3 , Dec 6, 2000
        • 0 Attachment
          c928400@... wrote:
          >
          > Thus wrote Devin Weaver (ktohg@...) on [001206]:
          > > 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')
          > endfun
          >
          > 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'
          > endfunction
          >
          > as this does not have the problem above (and you do not seem to mind
          > meddling with :norm anyway)
          >
          > Peppe

          You can also use "\<C-J>" (with the quotes!) instead of
          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
          '\s*'.nr2char(10).'\s*' .

          :help NL-used-for-Nul
          :help string

          HTH --Benji Fisher
        Your message has been successfully submitted and would be delivered to recipients shortly.