NERD commenter : How to comment out a range

后端 未结 4 722
深忆病人
深忆病人 2020-12-16 19:48

I am using NERD commenter

Let\'s say that I want to comment out lines from 78 to 172. This is what I do. I calculate the difference. That is 94. put my cursor on li

4条回答
  •  抹茶落季
    2020-12-16 20:19

    Sexy C comments mode

    Ranges of lines just work by default with visual selection + cc, tested on 2.5.2, as mentioned at: https://stackoverflow.com/a/1375070/895245

    But above all, I want to highlight in this answer the "sexy mode" comments with cs, which generates nice C multiline comments.

    For example, if you start with:

    This is a c style sexy comment
    So there!
    

    then cs from visual selection transforms it into:

    /* This is a c style sexy comment
     * So there! */
    

    And you can also switch to non-compact mode by adding to your .vimrc:

    let g:NERDCompactSexyComs = 0
    

    which works as follows:

    ------------------------------------------------------------------------------
    
                                                             *'NERDCompactSexyComs'*
    Values: 0 or 1.
    Default 0.
    
    Some people may want their sexy comments to be like this: >
        /* Hi There!
         * This is a sexy comment
         * in c */
    <
    As opposed to like this: >
        /*
         * Hi There!
         * This is a sexy comment
         * in c
         */
    

    Another related format which might be of interest is the "Minimal comment map" accessible with cm and which produces:

    /* Hi There!
       This is a sexy comment
       in C */
    

    I wasn't able to find my preferred style unfortunately:

    /* Hi There!
     * This is a sexy comment
     * in c
     */
    

    so I opened: https://github.com/scrooloose/nerdcommenter/issues/379

提交回复
热议问题