0

I am experiencing an issue where the code lines in VS Code appear normal, but when I push the code to GitHub, the lines become excessively long with horizontal scrolling. This happens particularly when writing comments.

Here how a portion of the code look in vs code

enter image description here

and here how it looks in github

enter image description here

Initially, both the editor and GitHub displayed long code lines. I adjusted the editor's settings, specifically the word-wrap property and word wrap column, hoping that it would also apply to GitHub. Unfortunately, the changes did not reflect on GitHub.

I am seeking a solution to ensure that the code appears consistently in both the code editor and on GitHub.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Abou Emran
  • 183
  • 2
  • 12
  • https://learn.microsoft.com/en-us/visualstudio/ide/reference/how-to-manage-word-wrap-in-the-editor?view=vs-2022 – Mark Schultheiss Apr 10 '23 at 20:45
  • No, it didn't. The Alt+Z option toggle the word-wrap and it makes them appear the same when word wrap is false (long lines in GitHub and the editor). but I want both have the short lines instead. – Abou Emran Apr 10 '23 at 20:54
  • 1
    the gap you see between line numbers `97` and `98` means all that text is one line – rioV8 Apr 10 '23 at 21:07
  • Does this answer your question [How can I Soft-wrap code in GitHub's file viewer?](https://stackoverflow.com/q/75186349/11107541) – starball Apr 10 '23 at 23:41
  • No, it didn't, but I get the concept of soft-wrapping from it, and after looking again at what I did in the settings. What I have done is called soft-wrapping which makes the appearance change only without inserting break line, and I searached for hard-wrapping and I found the answer in a question like this https://stackoverflow.com/questions/43122175/automatically-hard-wrap-lines-at-column-in-vscode – Abou Emran Apr 11 '23 at 03:11

1 Answers1

1

The lines are in fact excessively long. You need to add line breaks in your code. You've told VSCode to break lines where there aren't actually line breaks.

For example, pretend this is a very long comment:

# This is some very long comment

It should become something like this:

# This is some very
# long comment

Since you're using Python, you should be limiting the line length anyway; see PEP 8.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • This does solve the problem but requires adding explicit line breaks to split long lines, and this is fine when writing the comments myself. but when making an AI tool write the code comments for me, it becomes a tedious task to add these line breaks instead of having the editor add them when needed. – Abou Emran Apr 10 '23 at 21:08
  • While it may seem reasonable for line breaks to be added automatically, this would also cause the code to break. However, it would be helpful if there was a way to enable this behavior solely for comments in the code. – Abou Emran Apr 10 '23 at 21:14