tpope / vim-commentary

commentary.vim: comment stuff out
http://www.vim.org/scripts/script.php?script_id=3695
5.9k stars 214 forks source link

optional whitespace strip, ie. possibility to insert commentstring to the beginning of line #112

Closed habamax closed 5 years ago

habamax commented 5 years ago

Is it possible to setup it the way comment chars are inserted to beginning of line?

For Asciidoctor, comments should start with // at first column:

// this is comment
    // this is NOT comment

List:
* Item 1
    ** Item 2
    // This is not a comment
//     This is comment
    ** Item 3
habamax commented 5 years ago

Basically in s:go function:

...

    else
      if exists("b:comment_linestart")
        let comment_strip = '^'
      else
        let comment_strip = '^\s*'
      endif
      let line = substitute(line,'^\%('.matchstr(getline(lnum1),comment_strip).'\|\s*\)\zs.*\S\@<=','\=l.submatch(0).r','')
    endif
...

Then I can setup b:comment_linestart for asciidoctor filetype.

Would you accept a PR?

habamax commented 5 years ago

Fixed