junegunn / vim-easy-align

:sunflower: A Vim alignment plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: Provide a delimiter for comments

idbrii opened this issue · comments

I often have trouble using regular expressions with easy-align and I think I've tracked it down to #53: it's probably always with aligning comments.

Could easy-align provide a comment delimiter that uses commentstring to determine the pattern?

Something like this:

" Provide a / delimiter for the current filetype's comment marker.
augroup easyalign_comment
    au!
    au BufEnter * let g:easy_align_delimiters['/'] = { 'pattern': substitute(&commentstring, '%s.*', '', ''), 'ignore_groups': ['!Comment'] }
augroup END

I'm having problems figuring out how to comment this

  /* TCP A                                                TCP B */

/* 1.  CLOSED                                               LISTEN */

/* 2.  SYN-SENT    --> <SEQ=100><CTL=SYN>               --> SYN-RECEIVED */

/* 3. ESTABLISHED <-- <SEQ=300><ACK=101><CTL=SYN,ACK> <-- SYN-RECEIVED */

/* 4.  ESTABLISHED --> <SEQ=101><ACK=301><CTL=ACK>       --> ESTABLISHED */

/* 5.  ESTABLISHED --> <SEQ=101><ACK=301><CTL=ACK><DATA> --> ESTABLISHED */

    /*     Basic 3-Way Handshake for Connection Synchronization */

     /*                           Figure 7. */

I use tpopes commentary to make these comments.

@matthiasdebernardini Looks like the * in cpp's commentstring needs to be escaped.

Try this in the augroup I posted above:

au BufEnter * let g:easy_align_delimiters['/'] = { 'pattern': substitute(escape(&commentstring, '*'), '%s.*', '', ''), 'ignore_groups': ['!Comment'] }