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

dic / dc (and maybe yic/ pic / yc / pc) #111

Closed loshjawrence closed 5 years ago

loshjawrence commented 5 years ago

I was hoping this plugin supported something like dic/yic/pic but it appears it does not. If the cursor is in a contiguous set of single comments or a comment block it would be nice to support c as a text object for comments. I think dc/yc/pc should only affect the line the cursor is on, otherwise for the inner motion versions do something like the cases below.

Also, I think contiguous inline vs contiguous not-inline should be distinguished since I think most of the time this non-greedy approach is likely the intention of the user... and if the user wanted the greedy behavior they can just follow up with a . repeat.

cic could work but cc wouldn't follow the convention since it's already a core operation.

int y = 0; // Don't touch. 
// Touch
// Touch  // Cursor on inner 3 lines
// Touch
int x = 0; // Don't touch.
int y = 0;  // Don't touch.
/********************
 Touch. Cursor somewhere on the block comment
********************/ 
int x =0; // Don't touch.
int x =0; // Touch.
int y =0; // Touch. // Cursor on upper 3 lines
int z =0; // Touch.
// Don't touch
// Don't touch
// Don't touch
xaizek commented 5 years ago

I was hoping this plugin supported something like dic/yic/pic but it appears it does not.

Try dgc, etc.

Note that commentary does only whole line commenting, so your second and third examples don't work.

loshjawrence commented 5 years ago

'dgc' doesn't work for me. I tried vim-plug's :PlugClean and :PlugInstall but it still doesn't work, also checked my tagbar in my vimrc to make sure dgc isn't mapped to something else.

Edit Oh. by whole line commenting you mean it does this style / int x = 0; / and I can only operate on lines that have that style.

xaizek commented 5 years ago

It uses value of 'commentstring' option, you can change it to

setlocal commentstring=//\ %s

and it will work on // comment, but not on /* comment */.

tpope commented 5 years ago

Yep, dgc will delete comments created by gc. Commentary does not - and likely will never - support arbitrary comment syntax.

loshjawrence commented 5 years ago

Awesome thanks. This gets me what I need. Plug 'tpope/vim-commentary' autocmd FileType c,cpp,javascript,json setlocal commentstring=//\ %s