4
2
So my situation is that I have a file, myfile.py (written in python) that I started developing on my own machine. I used vim to do this, but at that time I did not know that Vim could let you define the length of your tabs, and also to show how many times the line had been tabbed by using a marker.
So before I SCP'ed myfile.py to a remote unix server and began working on it there, all my tabs were about 6 spaces in length each, and there were no markings defining how many indentations were present in a particular line. But since 6 spaces is a lot, there really was no need...
But when I began developing on the remote server, I noticed that their vim configurations had the tab so that it would be about 4 spaces in length each, and so that there would be vertical markings to show that a tab is present. However, it did not automatically change the lines of code that were already there in myfile.py to fit their tab-settings, and the settings ended up only applying to any new lines of code I wrote using vim on their server.
Being the newb that I was, I didn't bother to fix anything in order to make the file look consistent. Now I have some weird, interleaved-mixture where some lines have tabs that are 4 in length, others with 6, and the ones with shorter length have a vertical marking for each tab and the longer ones have nothing.
How do I efficiently fix this mess to revert back to one standard? (hopefully the one that has the shorter tab length with the vertical markings). I'm looking for anyone who has even remote experience regarding this predicament - whether this causes me to learn more vim on an advanced level, or start with some roundabout way first, I do not care. I just prefer anything over manually fixing each line - you know how wrong that could make your code when you're dealing with Python!
[EDIT]-> Also thought I should note that each line does not have the same number of tabs... some lines have 0, 1, 4, 5, etc etc...
write a python program that swaps out tabs for however many spaces... Or open the files in an IDE like Xcode with your tab preferences set to the new standard, select all text and re-indent... These are more elegant than manual. I like the first solution because you use a hammer to fix a hammer. – None – 2011-12-20T06:13:52.897
But not every line has the same number of tabs... some may just have 1, but there are some that even have 6! – Dark Templar – 2011-12-20T06:18:41.233
Try vimcasts.org. Episode 2 For tabs Episode 1 for showing hiddens
– Martin York – 2011-12-20T06:44:03.1274Did you try a simple
:retab!
already? – sebastiangeiger – 2011-12-20T07:02:13.643@sebastiangeiger - Thanks, I just tried that, since it was the simplest solution I've gotten so far - but it seems that what vim may be doing is chopping up the 6-length tabs into two (as denoted by the vertical markings :retab! has added; automatically adding in the vertical markings was part of my goal, so that is taken care of. The problem is that some lines where I was sure contained only one 6-length tab now shows up as containing TWO vertical marks) – Dark Templar – 2011-12-20T18:47:28.457
Hence that's why I suspect that command is just chopping up any tab that appears bigger. I originally left some comments when working on my own machine indicating that certain 6-length tabs were indeed only 1 tab :( – Dark Templar – 2011-12-20T18:51:58.107
Nevermind, I was tricked! The problem is that working on *my* machine had settings so that pressing the TAB button would insert TWO tabs (8 spaces). THAT's what the problem was! – Dark Templar – 2011-12-20T18:57:29.873
It's a shame that Python won't let you use *curly braces* to denote the start and end of a function or a block of code. The indentation rule just makes it confusing to debug files that are of at least a certain length!! – Dark Templar – 2011-12-20T19:06:35.867