NERD commenter : How to comment out a range

后端 未结 4 716
深忆病人
深忆病人 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:11

    I'd do (in visual mode) :78v172G to select and highlight lines 78 to 172, then just ,c<space>.

    0 讨论(0)
  • 2020-12-16 20:17

    It doesn't appear that NERDCommenter supports ranges, so Alex's answer would be correct, but he has a typo - it should be 78GV172G to select (note - no preceeding :), followed by your comment function ( in my case \cc).

    0 讨论(0)
  • 2020-12-16 20:19

    Sexy C comments mode

    Ranges of lines just work by default with visual selection + <leader>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 <leader>cs, which generates nice C multiline comments.

    For example, if you start with:

    This is a c style sexy comment
    So there!
    

    then <leader>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 <leader>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

    0 讨论(0)
  • 2020-12-16 20:21

    Enter Visual mode <ctrl> + V, using your arrow keys, highlight the lines you want then /c<space> (perhaps you have another key binded for commenting).

    0 讨论(0)
提交回复
热议问题