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

Textwidth and long outputs

Expand Messages
  • Torsten Andre
    Hi everyone, I just can t seem to get a hold of this. I would like VIM to break lines after 79 characters. So I used :set textwidth=79, which works like a
    Message 1 of 5 , Jun 30, 2009
    • 0 Attachment
      Hi everyone,

      I just can't seem to get a hold of this. I would like VIM to break lines
      after 79 characters. So I used :set textwidth=79, which works like a
      charm. The problem I have though, is when I want to print long messages.

      For example in python, when I write something like this:

      print "This is a very long line which is wrapped after 79 chars
      which may have happened just before these words and oh my, it
      happened again."

      Well, two things that annoy me a little bit. First of all the statement
      is not correct, since the interpreter gets to EOL without a proper
      ending of the statement. I manually need to include "\" so it's a valid
      statement. Is there a way around this? Can I have vim add a "\"?

      When executing the script, it will print the tabs/spaces vim includes
      just before "which" and "happened" in order to keep it aligned with the
      print command. But as you can assume that's the last thing I want.

      Wrapping the text using "wrap" and "wrapmargin" is not an option, since
      I need the text to be wrapped after 79 chars to be able to follow guide
      lines I have to obey in some projects.

      Is there a way around this problem? Or how do you guys deal with these
      kind of long strings? I mean not just in python, but in any language.

      Unfortunately I wasn't able to find anything on the web concerning this.

      Thanks for your help!

      Cheers,
      Torsten



      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • MK
      ... How you do need to do this may differ a little from one language to another, and depending on the nature of the statement. Really, the big deal with the
      Message 2 of 5 , Jun 30, 2009
      • 0 Attachment
        On 06/30/2009 06:23:28 AM, Torsten Andre wrote:

        > I need the text to be wrapped after 79 chars to be able to follow
        > guide
        > lines I have to obey in some projects.
        >
        > Is there a way around this problem? Or how do you guys deal with
        > these
        > kind of long strings? I mean not just in python, but in any language.

        How you do need to do this may differ a little from one language to
        another, and depending on the nature of the statement. Really, the
        big deal with the whitespace is only with a print" ", right? That
        is not really a vim problem, that is a python problem. There is
        nothing vim can do to change python from including all the whitespace
        between quotes.

        But, in some languages you could use:

        print "blah blah blah"
        +"blah blah";

        Notice the extra whitepace is not inside quotes now. Do you see what I
        mean about how it is a python issue, not a vim issue? I don't know
        python; if you cannot do this kind of thing there then you will have
        to split the print line into two print lines in order to conform to
        your guidelines.

        In other words, not all languagues permit you to break a print
        statement into two quoted segements, and there is no other way to do
        this. So you may need two seperate commands, or else don't indend the
        second half.

        WRT just adding a / at the end, there's probably a method and someone
        might post it. But generally, I think you will just have to write code
        that way to start with.






        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Charles Campbell
        ... Here you want vim to recognize that its in a non-terminated string and to append a before including the newline. ... [snip] And here, again, you want
        Message 3 of 5 , Jun 30, 2009
        • 0 Attachment
          Torsten Andre wrote:
          > Hi everyone,
          >
          > I just can't seem to get a hold of this. I would like VIM to break lines
          > after 79 characters. So I used :set textwidth=79, which works like a
          > charm. The problem I have though, is when I want to print long messages.
          >
          > For example in python, when I write something like this:
          >
          > print "This is a very long line which is wrapped after 79 chars
          > which may have happened just before these words and oh my, it
          > happened again."
          >
          > Well, two things that annoy me a little bit. First of all the statement
          > is not correct, since the interpreter gets to EOL without a proper
          > ending of the statement. I manually need to include "\" so it's a valid
          > statement. Is there a way around this? Can I have vim add a "\"?
          Here you want vim to recognize that its in a non-terminated string and to append a "\" before including the newline.

          > When executing the script, it will print the tabs/spaces vim includes
          > just before "which" and "happened" in order to keep it aligned with the
          > print command. But as you can assume that's the last thing I want.
          >
          [snip]

          And here, again, you want vim to recognize that a non-terminated string
          exists and to indent differently based on that.

          Assuming that you have syntax highlighting enabled, the information that
          a non-terminated string exists would be indicated by "pythonString"
          highlighting in effect at a newline boundary. Not saying that it would
          be easy, but perhaps you could modify vim72/indent/python.vim to do what
          you want. Don't modify the distribution file itself! Instead, copy it
          to $HOME/.vim/indent and modify your copy (that way updates to vim won't
          wipe out your work).

          Look into synIDattr() -- with that you can get the current syntax
          highlighting group (ie. pythonString).
          Use your modification to the python indenting to get the no-indent
          effect you want. You might be able to bend it enough to append the
          trailing backslash on the preceding line, too.

          Regards,
          Chip Campbell




          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • John Beckett
          ... Automatic wrapping is for when you are writing pure text (like this email). Do not use it for programming. In Python, your choices are: print Hello...
          Message 4 of 5 , Jun 30, 2009
          • 0 Attachment
            Torsten Andre wrote:
            > For example in python, when I write something like this:
            >
            > print "This is a very long line...."

            Automatic wrapping is for when you are writing pure text (like
            this email). Do not use it for programming.

            In Python, your choices are:

            print "Hello..." \
            "World..."

            and when you need a lot of text:

            LONG_MSG = """\
            Hello...
            World...
            """

            print LONG_MSG

            Use pylint (some Python extra, nothing to do with Vim) to find
            stuff you want to change, or use the following tip to find long
            lines:
            http://vim.wikia.com/wiki/Highlight_long_lines

            John


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Torsten Andre
            ... Thanks a lot everyone! I will deactivate this when writing code and do the wrapping manually. The tip about highlighting long lines is fantastic! Cheers,
            Message 5 of 5 , Jul 1, 2009
            • 0 Attachment
              John Beckett schrieb:
              > Torsten Andre wrote:
              >
              >> For example in python, when I write something like this:
              >>
              >> print "This is a very long line...."
              >>
              >
              > Automatic wrapping is for when you are writing pure text (like
              > this email). Do not use it for programming.
              >
              > In Python, your choices are:
              >
              > print "Hello..." \
              > "World..."
              >
              > and when you need a lot of text:
              >
              > LONG_MSG = """\
              > Hello...
              > World...
              > """
              >
              > print LONG_MSG
              >
              > Use pylint (some Python extra, nothing to do with Vim) to find
              > stuff you want to change, or use the following tip to find long
              > lines:
              > http://vim.wikia.com/wiki/Highlight_long_lines
              >
              > John
              >
              >
              > >

              Thanks a lot everyone! I will deactivate this when writing code and do
              the wrapping manually. The tip about highlighting long lines is fantastic!

              Cheers,
              Torsten

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            Your message has been successfully submitted and would be delivered to recipients shortly.