0

I frequently switch from working on my laptop to a school computer to a cluster machine Linux environment.

I get annoyed that code I write on Notepad++ on my laptop has different indents and spacing than the same code I open on my lab computer in Vim and vice versa.

For example, this code:

PetscInt            xs,xw,ys,yw;
PetscReal           lx,ly,dx,dy,dt,xp,yp;
PetscReal           sim_time;
DM                  da,daKSP;
Vec                 gv,lv,bv,X,lX;

Becomes this code:

    PetscInt        xs,xw,ys,yw;
PetscReal   lx,ly,dx,dy,dt,xp,yp;
PetscReal       sim_time;
DM                  da,daKSP;
Vec                 gv,lv,bv,X,lX;

Is there a process I can adopt so that my code pretty much looks the same from computer to computer?

Thank you

2 Answers2

2

Either make sure your softtabstop, tabstop, shiftwidth are the same as on your Notepad++, or make sure you use spaces, not tabs, for indentation (and set expandtabs in Vim).

I suggest adopting the latter solution, because tabs are a relic of the time when disk space was expensive, and because they are contextual and will mess up your code unless you have all the settings just right. Using spaces is foolproof, and all major editors support treating indentation spaces as if they were tabs anyway (e.g. deleting an indentation with a single backspace, converting Tab keypress into the appropriate amount of spaces, etc.) However, spaces vs. tabs is a matter of opinion/taste, and you might get the opposite recommendation elsewhere.

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

You can use http://editorconfig.org/ to maintain consistent configurations across editors and avoid such problems.

Dhruva Sagar
  • 7,089
  • 1
  • 25
  • 34