Search code examples
vimsublimetextviatom-editoradobe-brackets

Atom/vi - whitespace handling indiscrepencies


I am seeking an alternative to TextMate for my IDE of choice. I've tried a variety of other IDE's and have come to like Atom, but I'm still experiencing this particularly aggravating issue.

Once we push our projects to our production servers, and need to do edits via vi on the server, the whitespace is always more severe in vi than it was in the graphical IDE. For example in TextMate it looks like:

function foo(){
    var bar;
    if($this)
         ...
    else
         ...
}

Then in vi it's like this:

function foo(){
                var bar;
                if($this)
                        ...
                else
                        ...
}

It seems that TextMate encodes whitespace characters in a different encoding that vi recognizes as being much more substantial than it actually is. It's almost like vi doubles whatever the whitespace was in the graphical IDE. This is the whole reason for searching for another IDE.

Atom isn't nearly as bad about this, but it still presents similar issues. When opening files in Atom that have been edited with TextMate, the whitespace is totally screwed up as well. We use tab indentation as our in-house coding convention as opposed to two-space indentation. This won't be such an issue anymore once we settle on a new IDE, but my question is this:

Is there a plugin or a setting that needs to be adjusted so that whitespace is handled the same way across vi and graphical IDEs? Specifically in Atom

I'm open to other suggestions for IDEs that are compatible out of the box and share similar functionality to TextMate or Atom. We've also tried Brackets, SublimeText, and a handful of others.


Solution

  • It seems as if you are complaining that left-margin indentation width is not consistent between editors, or between your team members (or perhaps both).

    There is no blanket solution to this problem that you can magically apply. There are a couple of things you can try, though.

    1. Get consensus in your team about how to do indentation.

      If you expect consistency, everybody has to participate and agree what that means.

    2. Standardize on spaces for indentation instead of tabs.

      Tab characters are, by their nature, variable width, because each person can choose how to display them. For this reason, you can just banish them and use space indentation instead. The code will always display the same way.

      Some people complain about this idea, saying that they don't want to hit the spacebar all the time. But modern text editors handle this for you; you can still use your tab key and it works just fine.

      In many modern editors, this is called "soft tabs".

      In Vim, you can get this effect using something like

      :set tabstop=4 shiftwidth=4 softtabsstop=4 expandtab
      

      (Substitute your own number... 2, 8, whatever your team agrees on.)

    3. You can try EditorConfig.

      EditorConfig allows you to create a settings file that editors will use to configure various things, including indentation.

      It has plugins for most editors, which is convenient. However, it requires everyone use those plugins, which still requires a consensus, and everyone has to use the same config file (again, consensus).

      Some teams put their EditorConfig file in their code repo so it is easily shared.

    As for which editor / IDE to use, that is orthogonal to this question, really. You'll encounter this trouble whenever there are more than two text editors or team members involved.