Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment out a portion of a line #10

Open
adamm opened this issue Mar 10, 2012 · 9 comments
Open

Comment out a portion of a line #10

adamm opened this issue Mar 10, 2012 · 9 comments

Comments

@adamm
Copy link

adamm commented Mar 10, 2012

The vim-commentary documentation states three keyboard mapping examples to comment out whole lines of code, but I'm curious there is any plan to extending this plugin to support portions of a line.

Such as, for example, "\iw" would comment out only single word, and "{Visual}" comment out only highlighted words.

I can attempt to tackle this feature myself, but I'm no Tim Pope when it comes to Vim plugins :)

@adamm
Copy link
Author

adamm commented Mar 10, 2012

Oops, Github escaped by backslashes :) .. Obviously I meant "\iw" and "{Visual}\" respectively.

@tpope
Copy link
Owner

tpope commented Mar 10, 2012

I have no such plans. How often does this really come up? I'm trying to think of even one instance of wanting this.

@tpope
Copy link
Owner

tpope commented Mar 10, 2012

Mind you, I'm biased because like 90 percent of my code is in languages that only have linewise comments. But that raises the question of what happens in those languages.

@adamm
Copy link
Author

adamm commented Mar 10, 2012

Certainly language requirements dictate comment structure, but also personal coding style can avoid the need for partial line comments. To give you a specific example in C++, I was debugging a remote problem yesterday with the following block:

if (!first_run_ui_bypass && !force_first_run && !headless_setup &&
    (parsed_command_line.HasSwitch(switches::kApp) ||
     parsed_command_line.HasSwitch(switches::kAppId) ||
     parsed_command_line.HasSwitch(switches::kNoFirstRun)))
  first_run_ui_bypass = true;

I needed to bypass out the first two boolean checks, while maintaining the essence if block and bracket syntax. To do so, I was hoping to highlight only part of the first line, press "\", and produce this:

if (/*!first_run_ui_bypass && !force_first_run &&*/ !headless_setup &&
    (parsed_command_line.HasSwitch(switches::kApp) ||
     parsed_command_line.HasSwitch(switches::kAppId) ||
     parsed_command_line.HasSwitch(switches::kNoFirstRun)))
  first_run_ui_bypass = true;

Instead got this:

/* if (!first_run_ui_bypass && !force_first_run && !headless_setup && */
    (parsed_command_line.HasSwitch(switches::kApp) ||
     parsed_command_line.HasSwitch(switches::kAppId) ||
     parsed_command_line.HasSwitch(switches::kNoFirstRun)))
  first_run_ui_bypass = true;

Naturally I can fix this by hand, but then there's no benefit to using this plugin ;)

@tpope
Copy link
Owner

tpope commented Mar 15, 2012

Okay, well, I guess I'm not opposed to it, but I'm not very motivated to work on it either. And I'm kind of worried about how much complexity it will introduce.

One thing I am absolutely opposed to is configuration options for separate linewise and inline comments, because this means one of:

  • The user has to maintain a bunch of comment configuration options
  • The plugin has to maintain a bunch of comment configuration options

Both of those are unacceptable, in my book. Instead, we either have to parse 'comments', or limit support to a single comment syntax per file type.

This is a daunting task, so I feel like I should also inform you of tcomment, a commenting plugin that does pretty much everything.

@Alaya-in-Matrix
Copy link

Is there any way to comment a block instead of comment each line in the block?
for example, comment like this:

/*
int x = 3;
int y = 4;
*/
return 0;

instead of:

/* int x = 3; */
/* int y = 4; */
return 0;

@unphased
Copy link

unphased commented Jun 4, 2015

@Alaya-in-Matrix I think a separate issue is appropriate for a request like that (my comment on it is -- how might user choose which type of comment to apply? global config?)

And +1 for this issue. I often find a need to comment out a specific argument to a function call. It's very natural with argtextobj plugin: vaagc should comment out the arg under cursor.

@edi9999 edi9999 mentioned this issue Aug 19, 2016
@edi9999
Copy link

edi9999 commented Aug 19, 2016

Also would be interested in this, but I also understand that it wouldn't be very simple to develop and maintain

bokwoon95 added a commit to bokwoon95/.vim that referenced this issue Dec 1, 2018
vim-commentary doesn't support inline comments, while tcomment does. See
this PR: tpope/vim-commentary#10
CharlesGueunet added a commit to CharlesGueunet/vimmic that referenced this issue May 1, 2019
the missing endif had an impact on other plugins loading abilities
see: [vim-commentary issue:1109](tpope/vim-commentary#10]
@grepsuzette
Copy link

sounds like you could do this with vim-surround instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants