skip to Main Content

I’m working on a project that is using 2 spaces as indentation.
I have a hard time reading code with such small indentation, so my question is:

Question: Can I make vscode show the two spaces as if they were wider (for example double the width)?

(I could of course solve it in a hackish way, by converting each file on checkout, and convert it back before i commit it, but that would be very tedious and error prone. I could also try to convince the project to convert the whole project to tabs, so that everyone can use their own preferred indentation. But I don’t want to go into that discussion for every project I work on 🙂 )

2

Answers


  1. I think you can’t.

    There is no such setting in VS Code. As of version 1.13, you can change the kerning, but this changes the spacing between all characters. You cannot do this only for a single character (or a set of characters).

    The space width is a property of the font. Microsoft has a guideline that defines what is the ideal space size for a font. But this does not mean you cannot change it yourself when designing one. So I created a version of Roboto Mono which space character is 4x the original one.

    This works on Notepad and MS Word, we can see the space is quite big. However, using the exact same font in VS Code, the space is still small, independently of the font being monospaced or not.

    Illustration

    enter image description here

    Somehow, it looks like VS Code ignores space size in the font and decides by itself what is the best value.

    Login or Signup to reply.
  2. I have written the extension Indent Whitespace that decorates each space used in indentation with additional spaces (cursor will skip the decoration).

    The decorated spaces are colored with a very transparent red.

    enter image description here

    With a setting you can change the number of spaces to add, default 1.

    If you delete spaces with Delete it looks funny because the selection does not change, use the Arrow keys to update the decorations.

    In a later version I will make the decoration color a setting, and also only update the decoration when the file changes (only important for large files, and fix the delete-update rendering).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search