Skip to content

Instantly share code, notes, and snippets.

@PeterRincker
Created August 17, 2015 11:05
Show Gist options
  • Save PeterRincker/6e16e5a82065d7f9809f to your computer and use it in GitHub Desktop.
Save PeterRincker/6e16e5a82065d7f9809f to your computer and use it in GitHub Desktop.
Center text inside of a comment
" FancySmancyComment(text, fill_char, width)
" Create comment string with centered text
" All arguments are optional
function! FancySmancyComment(...)
let text = get(a:000, 0, '')
let fill = get(a:000, 1, '-')[0]
let width = get(a:000, 2, 80) - len(printf(&commentstring, '')) - len(text)
let left = width / 2
let right = width - left
put=printf(&commentstring, repeat(fill, left) . text . repeat(fill, right))
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment