Skip to content

Continue comment when enter is pressed #26694

Closed

Description

@jonhoo
  • VSCode Version: 1.12.1
  • OS Version: Arch Linux

Steps to Reproduce:

  1. Open editor in a language that supports comments (say foo.c)
  2. Type a line that starts with //
  3. Press enter
  4. Next line should automatically be started with // (or at least this should be possible to configure). Instead, the next line is empty.

Activity

  1. added
    feature-request
    editor-core
    on May 17, 2017
  2. PradeepKumarRajamanickam commented on May 17, 2017

    @PradeepKumarRajamanickam

    +1 this would be nice

  3. removed
    editor-core
    on May 26, 2017
  4. rebornix commented on May 26, 2017

    @rebornix
    Contributor

    This should be implemented in a C extension by customizing enter rules. We may want to update our internal C extension.

  5. added
    languages-basic
    good first issue
    and removed
    good first issue
    on Sep 18, 2018
  6. daltonamitchell commented on Dec 13, 2018

    @daltonamitchell

    Peng Lyu (@rebornix) If you can point me in the right direction for where to make these changes I'm happy to submit a PR for this. I like to start new files with comments laying out the code I'm going to write, so I'd get a lot of use from this.

  7. abettermap commented on Jan 17, 2019

    @abettermap

    Dalton A Mitchell (@daltonamitchell) I don't have any experience writing VS Code extensions, but here is a pull that implements it for Rust language. I also noticed that the Docker extension does it as well (although perhaps there is no concept of "block" comment in a Dockerfile):

    docker-multiline-comment

    ...and JavaScript does it natively (no additional extensions) for block comments:

    js-multiline-comment

    Hope that helps!

  8. removed their assignment
    on Oct 24, 2019
  9. 17 remaining items

  10. tim-hilt commented on Apr 19, 2024

    @tim-hilt

    Same for me. I'm quite confused tbh :D cyanophage are you sure that that's not a feature of a particular language-extension you're using?

  11. tomasklaen commented on May 23, 2024

    @tomasklaen

    Not just continue comment, but when I press "Join lines" shortcut, it should remove the comment prefix from the joined line.

    I remember having both of these in SublimeText and I still miss it even after yeas of vscode usage :(

  12. yuezk commented on Jul 22, 2024

    @yuezk

    Not just continue comment, but when I press "Join lines" shortcut, it should remove the comment prefix from the joined line.

    I remember having both of these in SublimeText and I still miss it even after yeas of vscode usage :(

    You got me there! I have this feature in Vim with a comment plugin, and it's super convenient. Every time I break a long comment line or join comment lines in VS Code, I think about this feature. I assumed there might be a configuration in VS Code, and finally stumbled upon this discussion.

    Hope VS Code will support this feature soon.

  13. starball5 commented on Nov 11, 2024

    @starball5
  14. aiday-mar commented on Dec 5, 2024

    @aiday-mar
    Collaborator

    Hi everyone, I have the following PR #235407 which should fix this issue for the following languages that use the double-slash line comment:

    • cpp
    • csharp
    • go
    • groovy
    • java
    • json
    • less
    • objective-c
    • php
    • rust
    • swift

    TypeScript and JavaScript already have this fix. This will add a line comment on the next line when pressing Enter only if the cursor is NOT followed only by whitespaces. This was decided as per a request from users after the fix came out for TypeScript/JavaScript. In other words, in the following case where | represents the cursor position, pressing enter will not add a line comment on the next line:

    // some comment |

    But in the following case it will

    // some | comment

    I have not added this change for C because we do not have a language configuration file for C and do not support auto-indentation natively for C. If there are other languages you'd like me to cover, with potential, other types of line comment syntaxes, please file a new issue.

  15. sbrocket commented on Dec 5, 2024

    @sbrocket

    This will add a line comment on the next line when pressing Enter only if the cursor is NOT followed only by whitespaces. This was decided as per a request from users after the fix came out for TypeScript/JavaScript.

    Can you clarify what the purpose of this is and why it makes sense to apply to the general feature? This seems like a non-obvious special case that will confuse people, but maybe I’m missing something.

  16. aiday-mar commented on Dec 5, 2024

    @aiday-mar
    Collaborator

    Hi Bryan Henry (@sbrocket) yes this is as a result of the following issue #233186 as well as comments in #180551 and generally feedback I have received in standup about not wanting to add a line comment on the next line if the cursor is at the end of the line followed only by whitespaces. The thought is that generally when one wants to write a multi-line comment, they'd probably use the multi-line format /* */. If however the cursor is within a line comment followed by non-whitespace characters, then we can assume the user wants to add a line comment on the next line.

    Additionally this would unify the experience generally with TypeScript and JavaScript.

  17. sbrocket commented on Dec 5, 2024

    @sbrocket

    this is as a result of the following issue #233186 as well as comments in #180551 and generally feedback I have received in standup about not wanting to add a line comment on the next line if the cursor is at the end of the line followed only by whitespaces

    I think this tells me why it was implemented this way (user feedback) but it’s still not obvious to me why people gave this feedback. What are the motivating use cases that make adding this exception better than not doing so?

    The thought is that generally when one wants to write a multi-line comment, they'd probably use the multi-line format /* */.

    This part feels a lot more like user preference than a safe assumption to make at the editor level. It’s not obvious to me that this is true generally for me at all.

    I would guess instead that it probably depends on whatever the style happens to be in an existing codebase, and so maybe even something I may want to configure at a workspace level? It’s honestly difficult for me to be sure of without sitting down and listing out use cases for both behaviors, but at minimum, if that assumption doesn’t hold true for any user then this behavior will seem non-obvious (aka “random” in confused user speak) and so it seems like it will be really annoying to those users.

    If however the cursor is within a line comment followed by non-whitespace characters, then we can assume the user wants to add a line comment on the next line.

    Yes this part does seem like a safe assumption.

  18. aiday-mar commented on Dec 6, 2024

    @aiday-mar
    Collaborator

    Yes essentially the feedback I got from the users I talked to was that they don't want a line comment to be inserted on the next line when pressing Enter from the end of a line comment. I think these users use the line comment to add single line comments (as generally the line comment was designed moreso for this purpose). For those users it can be disturbing to have to remove the double slash on Enter every time. I am open to discussion however and if a lot of people in this thread would like to add this functionality we can discuss it.

  19. aiday-mar commented on Dec 13, 2024

    @aiday-mar
    Collaborator

    This issue will be closed. Feel free to open other issues if there is something else.

  20. repulsio commented on Dec 19, 2024

    @repulsio

    Aiday Marlen Kyzy (@aiday-mar) How to disable this? This new feature is really disruptive to me

  21. aiday-mar commented on Jan 6, 2025

    @aiday-mar
    Collaborator

    Hi repulsio one way to disable this, is to install a language extension with a language configuration file that overrides the inbuilt language configuration file.

  22. locked and limited conversation to collaborators on Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-commentsfeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions