tpope / vim-commentary

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

Support commenting less than line #142

Open DoDoENT opened 3 years ago

DoDoENT commented 3 years ago

For example, gcw should comment only the next word. Also, if less than line is selected in visual mode, gc should comment out only the selection.

For example, consider this code:

void function( unsigned int var, unsigned char & errorCode );

After selecting only the errorCode word and pressing gc, or after positioning the cursor at the beginning of errorCode word and pressing gcw, the following state is expected:

void function( unsigned int var, unsigned char & /* errorCode */ );

However, I get the following:

// void function( unsingned int var, unsigned char & errorCode );

Note: I've setup // for line comments in c-like languages that support it with following .vimrc entry:

autocmd FileType cpp,hpp,ts,js,java,cs,groovy setlocal commentstring=//\ %s

However, I get the same wrong behaviour even if I set commentstring to /*\ %s\ */ (the entire line gets commented instead of just the selection).

rsynnest commented 2 years ago

Discussed in https://github.com/tpope/vim-commentary/issues/10