Click to See Complete Forum and Search --> : coding with vim
Col. Panic
12-10-2001, 05:36 PM
After a stint witn CodeCommander, I think I'm now back to vim, but I have a question:
Is there a way to make vim replace tabs with spaces (i.e. - hit the tab key and it puts in two space characters rather than a tab character)? I thought I heard that you could do that somewhere, but I've had no luck finding anything.
Thanks!
kmj
12-10-2001, 05:41 PM
try :set et
:)
Col. Panic
12-10-2001, 06:01 PM
Sure enough, that's what I was after. Thanks!
kmj
12-10-2001, 07:08 PM
no prob :)
Strogian
12-11-2001, 07:44 AM
I use :set shiftwidth=4 and then I use ^T for an indent, instead of a tab. (Sometimes I want to use a tab somewhere later in a line, and I don't just want four spaces to be inserted :))
recluse.
12-11-2001, 12:01 PM
Why would you want spaces instead of tabs? I think I heard a reason before, something about different tab settings in different programs(editors) but I'm not sure. Will someone set me on the correct path?
YaRness
12-11-2001, 12:32 PM
you SHOULD use tabs so that the spacing is dependent on the client (i.e. notepad or vim or emacs or whatever) and not the nut doing the coding.
kmj
12-11-2001, 01:06 PM
Originally posted by YaRness:
<STRONG>you SHOULD use tabs so that the spacing is dependent on the client (i.e. notepad or vim or emacs or whatever) and not the nut doing the coding.</STRONG>
well, that's debatable... for example, at RIT there are strict limitions on the length of a line (no more than 80 chars), and you will be penalized if you exceed them. I hate 8 space tabs, so I always have my ts=4. Now, when the prof opens up my code, if his ts=8 my lines may suddenly be extended by up to 16 spaces. This could cause me to loose points. If I use spaces instead of tabs, the lines will remain the same, thereby not causing me to loose points. Annoying, but that's the way it works.
YaRness
12-11-2001, 01:11 PM
merely a client-side issue. it'd take one or two lines of code to write a script to turn all the leading tabs into X spaces.
tabbing is still the more configurable method of doing it (that is, the user can decide how many spaces across the tabs are displayed).
additionally, if your prof is turning your single-character tabs into multiple space characters, and THEN penalizing you for too many spaces, that's just plain unfair anyway, not to mention an extremely unique exception to the usefulness of tabs. not much of an argument against using tabs.
[ 11 December 2001: Message edited by: YaRness ]
kmj
12-11-2001, 01:34 PM
Originally posted by YaRness:
<STRONG>merely a client-side issue. it'd take one or two lines of code to write a script to turn all the leading tabs into X spaces.
tabbing is still the more configurable method of doing it (that is, the user can decide how many spaces across the tabs are displayed).
additionally, if your prof is turning your single-character tabs into multiple space characters, and THEN penalizing you for too many spaces, that's just plain unfair anyway, not to mention an extremely unique exception to the usefulness of tabs. not much of an argument against using tabs.
[ 11 December 2001: Message edited by: YaRness ]</STRONG>
It's easier to just make your tabs equal to 4 spaces than to remember to modify your code before each submission.
Also, the line-length issue isn't unique, it can happen in any environment where two different people have to look at code. It's a conflict of preferences: do you want to look at code with the same depth of indentation, always; or do you want to make sure that your code doesn't extend beyond the width of your editor, which can be very annoying.
You misunderstood what I said. When my tabstop is set to 4, and the professor's (or grader's) tabstop is set to 8 (the default for vim), this doubles the width of each tab character. 4 tab characters now equals 32 spaces (almost half an 80 char line) instead of 16. That's an increase of 16 spaces, but the same amount of characters.
Also note that some programs don't allow you to change the value of the tabstop. If for some god-awful reason you have to look at some code in notepad, then you're stuck with 8 space tabs.
Please note that I do use tabs, pretty much without exception, not spaces. But it is a matter of preference, just like what editor you choose to use. I really have never heard a very solid argument for either method.
YaRness
12-11-2001, 02:14 PM
just having some fun, i really don't care if you use tabs or not :P
Originally posted by kmj:
<STRONG>Also note that some programs don't allow you to change the value of the tabstop. If for some god-awful reason you have to look at some code in notepad, then you're stuck with 8 space tabs.</STRONG>considering the fact that VIM works on pretty much every platform, that's just a lazy excuse :D
TheLinuxDuck
12-11-2001, 03:35 PM
At the risk of risking the at, I am an advocate of using only spaces.
I have several reasons for using spaces only.
1. No matter what platform, what editor, what source code, what settings of the editor, a space is a space is a space. You hit the spacebar once, the cursor moves forward one space. You hit the backspace, the cursor moves back one space.
2. Most people tend to use 4+ sized tabs. The more intended code is, the less space that you have to actually write code in an 80
column terminal. I use a 2-space indentation policy that is readable, concise, and I have the maximum amount of column width to write code.
3. One thing I hate more than anything is backspacing through a piece of code only to have the cursor hit a number of tabs, and the cursor ends up deleting portions of my code. With spaces, I know how many places the cursor is going to go at all times, and I don't have to worry about hitting a pocket of tabs and erasing something I shouldn't have erased.
The truth is, it's a matter of preference. There is no right way or wrong way. We could argue til we were blue in the face as to the merits of one method or another. it's similar to arguing about which editor is best. There just isn't a right answer. People should do what they feel comfortable with.. but, you had better be warned... if you send me code to edit, it's going to come back to you with only spaces in it. (^=
YaRness
12-11-2001, 04:18 PM
i'm so bored and pissed off at stupid 2000 server, i need something to do:
>>1. No matter what platform, what editor, what source code, what settings of the editor, a space is a space is a space. You hit the spacebar once, the cursor moves forward one space. You hit the backspace, the cursor moves back one space.
when exactly is a tab not a tab? if your editor sucks that's a problem a person should fix. www.vim.org (http://www.vim.org) :D
>>3. One thing I hate more than anything is backspacing through a piece of code only to have the cursor hit a number of tabs, and the cursor ends up deleting portions of my code.
uhh, like, slow down cowboy! or see above about your editor sucking. or something.
>>There is no right way or wrong way.
of course there is! there's MY way, and the wrong way.
>>if you send me code to edit, it's going to come back to you with only spaces in it.
s/^\s{2}/"\t"/ge foreach (<> ) #or something like that
Strogian
12-11-2001, 05:20 PM
I was convinced at an early age that a tab is 8 spaces. :) I think it was in the elvis documentation that it said that changing the tab length could be problematic. One of the things I remember from it is that printers would always interpret a tab as 8 spaces, and therefore your code would look screwy if you had it set any other way. So, I use :set shiftwidth=4 and assume that everyone else is using a tab width of 8. If they're not, that's their own problem. They're the ones breaking the law, not me. :)
Col. Panic
12-11-2001, 09:57 PM
Originally posted by TheLinuxDuck:
<STRONG>At the risk of risking the at, I am an advocate of using only spaces.
I have several reasons for using spaces only.
1. No matter what platform, what editor, what source code, what settings of the editor, a space is a space is a space. You hit the spacebar once, the cursor moves forward one space. You hit the backspace, the cursor moves back one space.
2. Most people tend to use 4+ sized tabs. The more intended code is, the less space that you have to actually write code in an 80
column terminal. I use a 2-space indentation policy that is readable, concise, and I have the maximum amount of column width to write code.
3. One thing I hate more than anything is backspacing through a piece of code only to have the cursor hit a number of tabs, and the cursor ends up deleting portions of my code. With spaces, I know how many places the cursor is going to go at all times, and I don't have to worry about hitting a pocket of tabs and erasing something I shouldn't have erased.
The truth is, it's a matter of preference. There is no right way or wrong way. We could argue til we were blue in the face as to the merits of one method or another. it's similar to arguing about which editor is best. There just isn't a right answer. People should do what they feel comfortable with.. but, you had better be warned... if you send me code to edit, it's going to come back to you with only spaces in it. (^=</STRONG>
Duck, I think you and I are sharing the same brain.
(Could I have use of it from 9:10-11:10 on Thursday? I have a final.)
Niminator
12-12-2001, 12:56 AM
I think spacing is definitely the way to gok to control the format of your program. Tabs are different all over the place, or worse for us nonstandard 2-space tab guys, they are the same. So for every tool you use, you have to figure out how to make the tab indention 2 spaces instead of the godawful 8. It's just nicer to change platforms and get right into the code, instead of spending 5 or 10 minutes looking up how to set tab spacing properties. I program on a lot of different os's (well 2) and I print some of my programs out at school from MS Word and I pay a hefty price if I forget to do a %s/^t/ /g in vim before I copy the code onto a disk and print it from Notepad or Word.
justlinux.com
Copyright Internet.com Inc. All Rights Reserved.