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

Possible to auto add / to end of line when vim reaches textwidth and does a new line?

Expand Messages
  • David Woodfall
    Hi When I m writing shell scripts I tend to have textwidth at around 72 characters. Is there a way that vim can auto add a at the end of the line when it
    Message 1 of 4 , Apr 24, 2014
    • 0 Attachment
      Hi

      When I'm writing shell scripts I tend to have textwidth at around 72
      characters. Is there a way that vim can auto add a \ at the end of the
      line when it starts a new line?

      Thanks

      --
      Studioware. We provide the tools - You make the music.
      http://www.studioware.org
      irc.freenode.net #studioware
      irc.oftc.net #studioware

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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Ben Fritz
      ... I think you can use the formatexpr option for this. You ll need to write a function to do your formatting for you, including breaking the line and adding
      Message 2 of 4 , Apr 25, 2014
      • 0 Attachment
        On Thursday, April 24, 2014 1:15:23 PM UTC-5, slack woody wrote:
        > Hi
        >
        >
        >
        > When I'm writing shell scripts I tend to have textwidth at around 72
        >
        > characters. Is there a way that vim can auto add a \ at the end of the
        >
        > line when it starts a new line?
        >

        I think you can use the 'formatexpr' option for this. You'll need to write a function to do your formatting for you, including breaking the line and adding the '\'.

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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • David Woodfall
        ... Thanks, I ll look into that. -Dave -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
        Message 3 of 4 , Apr 25, 2014
        • 0 Attachment
          >On Thursday, April 24, 2014 1:15:23 PM UTC-5, slack woody wrote:
          >> Hi
          >>
          >>
          >>
          >> When I'm writing shell scripts I tend to have textwidth at around 72
          >>
          >> characters. Is there a way that vim can auto add a \ at the end of the
          >>
          >> line when it starts a new line?
          >>
          >
          >I think you can use the 'formatexpr' option for this. You'll need to write a function to do your formatting for you, including breaking the line and adding the '\'.

          Thanks, I'll look into that.

          -Dave

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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • David Woodfall
          ... Well, I ve almost got something to work, but it behaves in a strange way. I set it to split at 10 characters for testing: set formatexpr=EndLine() fun
          Message 4 of 4 , Apr 26, 2014
          • 0 Attachment
            >> When I'm writing shell scripts I tend to have textwidth at around 72
            >>
            >> characters. Is there a way that vim can auto add a \ at the end of the
            >>
            >> line when it starts a new line?
            >>
            >
            >I think you can use the 'formatexpr' option for this. You'll need to write a function to do your formatting for you, including breaking the line and adding the '\'.

            Well, I've almost got something to work, but it behaves in a
            strange way. I set it to split at 10 characters for testing:

            set formatexpr=EndLine()

            fun EndLine()
            let c = col(".")

            if c == 10
            exec "normal Bh"
            exec "normal i \\\<CR>"
            exec "normal $A"
            return
            endif
            endfun

            When I type a long line it swaps the last 2 letters for some reason
            that I can't figure out. 'acdefghij' changes to 'abcdefghji'.

            Also, if I use '> 10' rather than '== 10' it spits out about 100 lines
            of '\', as if the cursor position hasn't updated. I tried using
            setpos() but that had no effect.

            I expect there are much better ways of doing this so if anyone has any
            suggestions I'd be glad for the help.

            Thanks

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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          Your message has been successfully submitted and would be delivered to recipients shortly.