helix icon indicating copy to clipboard operation
helix copied to clipboard

Granular commenting

Open txtyash opened this issue 2 years ago • 14 comments

Selections in line can't be commented. The entire line gets commented. Granular control with C-c would fix this.

txtyash avatar Sep 28 '22 17:09 txtyash

Would this just insert a comment marker to the left of the cursor?

dead10ck avatar Sep 28 '22 17:09 dead10ck

There's some plugin in lunarvim that comments text using gc<movement> or visual selection and gc So here,

This part|[cursor]is

|(cursor) & [] is the selection. Running C-c here should comment the word "cursor":

This part #cursor is

I'm not saying that this is a clever binding. This is just the idea. If planned, then better bindings could be implemented.

txtyash avatar Sep 28 '22 17:09 txtyash

I actually like the current behavior. If this is implemented I'd prefer it as a separate command.

CptPotato avatar Sep 29 '22 07:09 CptPotato

I actually like the current behavior. If this is implemented I'd prefer it as a separate command.

Yes, the current behavior is short and fast. I don't want this feature to slow down or interfere with the current implementation.

txtyash avatar Sep 29 '22 07:09 txtyash

I think that for languages which support it, an option could be added to comment only the selection (from your example it appears as though the comment is from #cursor to the end of the line).

So for

This part|[cursor]is

|(cursor) & [] is the selection.

you'd have:

  1. Comment from selection to end of the line
This part #cursor is
  1. Comment only the selection
This part /*cursor*/ is

filipdutescu avatar Oct 11 '22 21:10 filipdutescu

How about implementing a toggle_block_comments without touching the toggle_comments like vscode?

AK-10 avatar Nov 27 '22 06:11 AK-10

I'm trying implement the toggle_block_comments command

AK-10 avatar Nov 27 '22 06:11 AK-10

I actually have mostly implemented that if you want to take a look: #4718

gabydd avatar Nov 27 '22 07:11 gabydd

I would say it's pretty much fully implemented I just need to add tests and add it to the docs

gabydd avatar Nov 27 '22 07:11 gabydd

@gabydd Oh, looks pretty good! But I think it behaves a little differently than toggle

I think vscode's Toggle Block Comment behaves as toggle

https://user-images.githubusercontent.com/27846333/204569530-bb167b9b-e314-4bc4-8ffd-6c0bb677c407.mp4

AK-10 avatar Nov 29 '22 15:11 AK-10

Yeah at this moment the surrounding tokens need to be inside the selection, but i think I should be able to get it to search past whitespace surrounding a selection for comment tokens

gabydd avatar Nov 29 '22 15:11 gabydd

Looks like this can be closed now that #4718 is merged?

<space>-C - block comment selection mac + Ctrl-c - select around block comment and uncomment

Works like a charm, thanks a ton @gabydd!

cotneit avatar Feb 29 '24 04:02 cotneit

We might want to have <space>-C be granular even if there isn't a block comment token for the language so you can use that to comment in the middle of a line

gabydd avatar Feb 29 '24 05:02 gabydd

That sounds reasonably useful to me but there is no way we find this issue. @gabydd could you make an issue that describes that specific subtasks and close this one. I think the main concerns here have been addressed and I usually feel that followup work is better of in its own issues

pascalkuthe avatar Apr 07 '24 01:04 pascalkuthe