Skip to content

Instantly share code, notes, and snippets.

@Phize
Created February 1, 2012 08:25
Show Gist options
  • Save Phize/1715941 to your computer and use it in GitHub Desktop.
Save Phize/1715941 to your computer and use it in GitHub Desktop.
align comment(s) with Align Them All! plugin on Vim.
" return regexp pattern that matches a comment based on commentstring.
function! s:getCommentStringPattern()
let pattern = escape(&commentstring, '^$[].*\~ ')
let pattern = substitute(pattern, '%s', '.*', 'g')
return pattern
endfunction
" align comment(s) based on commentstring.
autocmd vimrc-autocmd BufEnter *
\ execute 'nnoremap <silent> <Leader>a/ :<C-u>Alignta v/^\s*' . s:getCommentStringPattern() . ' <-- -r ' . s:getCommentStringPattern() . '<CR>' |
\ execute 'vnoremap <silent> <Leader>a/ :Alignta v/^\s*' . s:getCommentStringPattern() . ' <-- -r ' . s:getCommentStringPattern() . '<CR>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment