On 21 April 2016, LCD 47 <lcd047@gmail.com> wrote:
> On 20 April 2016, Mike K. <lists@koralatov.com> wrote:
> > I'm trying to work out how to make vim right-align comments in my
> > various config files whilst leaving the rest of the line where it is.
> >
> > Here's what my .muttrc currently looks like:
> >
> > set attribution = "* %n wrote on %D:" # Date in ISO 8601 format
> > set include = yes # Include original message in reply
> > set indent_string = "> " # Use `>' as quote character
> > set nomarkers # Don't add marker to wrapped lines
> >
> > And here's what I'm trying to make it look like:
> >
> > set attribution = "* %n wrote on %D:" # Date in ISO 8601 format
> > set include = yes # Include original message in reply
> > set indent_string = "> " # Use `>' as quote character
> > set nomarkers # Don't add marker to wrapped lines
> >
> > So, my question is this: is it possible to get vim to insert the
> > required number of spaces to get all the text after the `#' to align
> > on the right, say in column 78? I've tried googling and came up with
> > nothing.
>
> Yeah, you can do it if you're really determined. Add this to your
> vimrc:
>
>
> function! Hashalign(text)
> let width = strdisplaywidth(a:text)
> return width < &tw ? substitute(a:text, '^.\{-}\\\@<!\%(\\\\\)*\zs\ze#',
> \ repeat(' ', &tw - width), '') : a:text
> endfunction
>
> autocmd BufWritePre *
> \ if &ft ==# 'muttrc' |
> \ %s/.*\\\@<!\%(\\\\\)*#.*/\=Hashalign(submatch(0))/ |
> \ endif
[...]
> The result is still flawed, since tabs inside comments can still mess
> up alignment. Fixing that is left as an exercise. :)
Also, # in single or double quotes will also be messed up. Fixing
that is also left as an exercise.
/lcd
--
--
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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wednesday, April 20, 2016
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment