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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to