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

Re: Join Lines in Paragraph

Expand Messages
  • Tony Mechelynck
    ... Try the following (untested): 1. Temporary set textwidth to a huge value, bigger than the length of your longest paragraph. 2. In Normal mode, do gggqG
    Message 1 of 4 , Jun 3, 2010
    • 0 Attachment
      On 03/06/10 07:11, Danko Krajisnik wrote:
      > Hello,
      > First off, allow me to explain my desired usage. Normally, when editing
      > text, I have vim set to wrap at 79 characters and auto-format with
      > fo+=a. This means that actual newlines are present in the file. This
      > works well since most vim commands are designed with real lines in mind.
      > Now, when I want to copy the text into an MS Word document or send it to
      > some non-vim user, I need to have the actual newlines removed and each
      > paragraph to be joined into a single line. I would prefer to put this
      > functionality into a function that would be able to "convert" the whole
      > file in one action.
      > I have read usr_25, which gives some hints about this but the commands
      > in that document simply do not work for me. I get "E486: Pattern not
      > found: ^$".
      > To specify more precisely, what I want is that each block of text
      > separated by an empty line is converted into a single line and that the
      > empty line remain. Ideally, it would also be able to recognize lists and
      > NOT join those lines together.
      > Thanks in advance for your help.

      Try the following (untested):

      1. Temporary set 'textwidth' to a huge value, bigger than the length of
      your longest paragraph.

      2. In Normal mode, do

      3. Export your file (e.g., copy it to some other name or directory using
      :saveas (q.v.))

      4. To reset it as it used to be, use u (undo), then set 'textwidth' back
      to 79 (or to whatever you prefer).

      This would mean the following (untested) command

      command -bang -bar -range=% -nargs=1 -complete=file
      \ ExportLongLines
      \ <line1>,<line2>call s:Export(<q-args>, <q-bang>)
      function s:Export(fname, bang) range
      let save_tw = &tw
      set tw=2147483647 " maximum possible line size
      exe a:firstline
      exe 'normal m[VG' . a:lastline . 'm]gq'
      exe "'[,']w" . a:bang a:fname
      let &tw = save_tw

      which you would call as

      :[range]ExportLongLines[!] {file}

      [range] = lines to be operated on (default whole file)
      [!] = if ! used, overwrite an existing file even if readonly
      if not used, do not overwrite etc.
      {file} = file where the long lines are to be written

      Best regards,
      It is better never to have been born. But who among us has such luck?
      One in a million, perhaps.

      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
    Your message has been successfully submitted and would be delivered to recipients shortly.