I've Switched To Spaces
bamccaig

I used to always prefer tabs for indentation, but after struggling with alignment for so long and also learning a bit of Python, which benefits from spaces, I've decided to switch completely over to spaces.

Now we can have another tabs vs. spaces flame war, but now I've switched sides... :P

** EDIT **

I'm so used to Tab meaning a tab character that I keep instinctively using the Space bar to indent now... :-X

Thomas Fjellstrom

I press tab for indent. regardless of what it means in any given project (my projects tend to use literal tabs, displayed at 3 spaces).

bamccaig

I've configured Vim to use spaces to indent, but I just instinctively hit the Space bar 4 times instead of tab... It's starting to make me struggle at j0rb too cause they use tabs there (and they probably haven't reached a point yet where spaces make sense), but I'm starting to get used to using spaces. My environments have always been configured to use tabs, so whenever I used to use spaces to indent (mainly here on Allegro.cc and I suppose recently in Python) I would do so manually with the Space bar; so I started doing that at j0rb the past couple of days. Once I get used to using the tab key for spaces for my own stuff, it should be less of a problem because it should just work most of the time at j0rb (cause it's configured for tabs there) the same as it does at home (which will be configured for spaces). The difference should often be transparent.

ReyBrujo

I use tab, but let Vim translate those to spaces. I simply detest tab, especially when people use some "odd" tabulation (like 3 spaces, so they combine tab and spaces when having more than 2 or 3 indentation levels).

DanielH

Since the dawn of time...

I've been programming for a long time now and have always used spaces. Recently, a couple of months, I switched to tabs to see how I would feel. I like tabs better.

Thomas Fjellstrom

I haven't seen a decent editor that would let you move properly through text when spaces are used for indentation, so I try not to use them. Its annoying. Have to press the arrow key for each space. Thats how people get carpal-tunnel for peat's sake.

ReyBrujo

Well, if you are not going to make puns, Vim lets you move to the first non blank character of the line (similar to what some Microsoft IDEs do when you press Home, you go to the first non blank character instead of the start of the line). Most editors let you skip all the blanks with CTRL+LEFT, for example.

Shravan

I would use spaces between the words of a program and tabs whenever a new block begins.Tabs increase the readability of the code.

Peter Wang

I haven't seen a decent editor that would let you move properly through text when spaces are used for indentation, so I try not to use them. Its annoying. Have to press the arrow key for each space. Thats how people get carpal-tunnel for peat's sake.

Right, don't do that. As Rey says, skip entire words at a time. But I wonder why you need to be cursoring over indentation anyway. Every editor I've ever used (except maybe notepad) at least lets you jump to the start of the line past the indentation, if it doesn't place you there already.

Another vi/vim tip to avoid cursoring (and this is one I didn't know for a long time): the 'f' command lets you skip directly to the next occurrence of a character on the line, e.g. f, skips to the next comma. 'F' goes in the other direction.

Thomas Fjellstrom

Right, don't do that. As Rey says, skip entire words at a time. But I wonder why you need to be cursoring over indentation anyway. Every editor I've ever used (except maybe notepad) at least lets you jump to the start of the line past the indentation, if it doesn't place you there already.

Modifying indentation for one. CTRL+LEFT is rather hard to press on my laptop, and it goes up to the next line, I rarely want that. I'm trying to navigate around the beginning of the line. If I wanted to navigate to the prior line, I'd press up and maybe end, not CTRL+LEFT a bunch of times.

Also, if you set your editor to display whitespace, all those little dots in the indentation gets to be quite distracting. I'd prefer one per indentation level (which is what a hard tab gives you), not one per space ::) (which is what space indentation gives you).

Also, I don't use any variant of vi or emacs. Too much a pain in the ass. And yes I tried learning it. Didn't find it worth the effort. I like a good gui editor that blends into my desktop. Not some console editor (except nano for quick ssh editing), or some hacked up mashup (aka gvim). I just don't like either editor very much.

Now those aren't the only reasons I've found I had to cursor over the leading white space, just all I could think of at the moment.

Also, "Right don't do that" is not a solution. I'm tired of people providing that as a solution to things, that really do have a valid alternative.

Peter Wang

Just trying to save some wrists.

Martin Kalbfuß

Classic tabs with a length of 8 spaces.
I let gedit show me tabs and spaces. This way I can see my mistakes. This works well for python, too. If you don't like how it looks. You can switch it on, only if you want to check your indentation.

Thomas Harte

Nothing but tabs for me, same as I wouldn't use two hyphens to make an emdash. Actually, scratch that comparison - I've never understood why anyone thinks this decision is anything other than personal preference.

And, yes, it does make me feel bad when I post from my iPhone like now and the only dash easily available is a plain hyphen.

Evert

Modifying indentation for one.

Well. Any one of <<, == or >> in vim will do that for me (which to use depends on what exactly I need to correct). For entire blocks =i} or =i{ does very well too.

Quote:

Also, I don't use any variant of vi or emacs. Too much a pain in the ass. And yes I tried learning it. Didn't find it worth the effort.

To each his own. Learning to use vim somewhat properly has probably been the most useful time investment I've ever made when it comes to using a computer (probably comparable to learning Perl - between Perl and vim I'm not sure how I managed to use a computer before).

Quote:

I like a good gui editor that blends into my desktop.

Personally I like a good editor. :P

Quote:

Not some console editor (except nano for quick ssh editing), or some hacked up mashup (aka gvim).

Huh? To what specifically are you referring?

Quote:

Also, "Right don't do that" is not a solution. I'm tired of people providing that as a solution to things, that really do have a valid alternative.

Well, you said "I haven't seen a decent editor that would let you move properly through text when spaces are used for indentation". Vim lets you do exactly that.

james_lohr

I used to use spaces in old crappy IDEs, but I use tabs now since most modern IDEs are intelligent enough to allow spaces and tabs to be used interchangeably with minimal hassle.

bamccaig

I haven't quite learned to properly navigate through the text in Vim, but I have seen it demonstrated just how easy it is if you know how. It's so much faster to do anything than in a conventional editor. That's why I stick to Vim whenever I can. I'm slowly trying to learn how to use it properly... It would be nice to take an actual course in it actually, but otherwise finding the time to run through decent tutorials should be fine.

Thomas Harte

Yes, I think the last time I deliberately used spaces was back in ye olde days of RHide.

EDIT: that Jef Raskin(-inspired?) editor has the fastest text navigation I've ever used. Hold down a modifier and type, the editor jumps to the next instance of that text. Hold down an alternative modifier and it'll search for the previous instance.

Timorg

I prefer 4 spaces for tabs, and in the editor (Code::Blocks) they act as spaces, but when the file is saved they are converted to tabs. That way if I edit the file with Vim it still works out ok.

ReyBrujo

Classic tabs with a length of 8 spaces.

8 spaces is too large for me. 3 is odd, so I prefer 4.

Hold down a modifier and type, the editor jumps to the next instance of that text. Hold down an alternative modifier and it'll search for the previous instance.

You use / to search forward in Vim, and ? to search backwards. Even Firefox uses / for quick search.

Sirocco

I love the TAB key. What I love most is that when I press it, four spaces are inserted into my code instead. Fuck yeah.

Thomas Harte
ReyBrujo said:

You use / to search forward in Vim, and ? to search backwards

That's modal rather than quasimodal, which means that it takes more mental processing to make reflexive. Modal = need to keep more in your mind at once.

Essentially though, it's nice that bamccaig and I agree, even if I didn't realise it.

EDIT: I guess it's like the difference between CAPS LOCK and using the shift key. Except for a feature that you probably use much less frequently.

Indeterminatus

Use code formatting tools. Focus your worries on something else (meaning, more important).

\o/

bamccaig

Ooh, I've just discovered tagging in Vim! \o/ Generate a tags file with ctags (not sure if it only supports C or if it has support for other languages... Maybe there are similar commands for other languages).

[bamccaig@rufus trunk]$ ctags `find -name \*.h -o -name \*.c`
[bamccaig@rufus trunk]$ vim tests/bam_list_test/src/main.c

From within Vim:

:tag bam_list_create

Vim automatically finds the definition of bam_list_create in src/bam_list.c (technically it just matches it in the tags file) and opens it. ;D

** EDIT **

[bamccaig@rufus trunk]$ ctags --list-languages
Asm
Asp
Awk
Basic
BETA
C
C++
C#
Cobol
Eiffel
Erlang
Fortran
HTML
Java
JavaScript
Lisp
Lua
Make
Pascal
Perl
PHP
Python
REXX
Ruby
Scheme
Sh
SLang
SML
SQL
Tcl
Vera
Verilog
Vim
YACC
[bamccaig@rufus trunk]$ 

Nvm. ;D

Thomas Fjellstrom

I really don't know why people continue to give vim examples to me. I don't use it, and likely never will :P

Thomas Harte

That example at least undercuts anyone who might assume that text based software is inherently less featured. Though I doubt anyone here would. You know, other than making general observations about the correlations between launch date and probability of software being text based and between launch date and the probability of software having <arbitrary feature>.

Evert

I really don't know why people continue to give vim examples to me. I don't use it, and likely never will :P

Probably because you complain about editors not being able to do such and so while vim can do such and so easily. ;)

gnolam

quasimodal

An interface making extensive use of \a?

Thomas Harte
gnolam said:

An interface making extensive use of \a?

Not so much using it as just going on about it tediously. Never invite a quasimodal interface to a dinner party.

Thomas Fjellstrom
Evert said:

Probably because you complain about editors not being able to do such and so while vim can do such and so easily. ;)

I didn't say editors couldn't modify indentation ::) I said thats one reason I move around in leading white space.

Even kate has a short cut for modifying indentation. I can never remember all of the extra shortcuts though (one reason why vi/emacs would be USELESS for me), so I tend to just do things manually.

ReyBrujo
bamccaig said:

Ooh, I've just discovered tagging in Vim!

It is kind of obsolete now that Vim features native intellisense, but it is still pretty powerful.

By the way, I thought you were talking about marks (using m[a-zA-Z] to mark a position in the file, then '[a-zA-Z] to go to the mark).

bamccaig
ReyBrujo said:

It is kind of obsolete now that Vim features native intellisense, but it is still pretty powerful.

Yeah, but I haven't gotten that far yet. :P Besides, even in Visual Studio I find myself using the "Go To Definition" feature relatively often.

You wouldn't happen to know the relevant commands/configuration settings, or even better a tutorial or reference, for getting intellisense configured in Vim?

** EDIT **

Making some progress, maybe. While in insert mode, press CTRL-X to enter CTRL-X mode where it seems the insert completion functionality is. More can be found with :h ins_completion.

ReyBrujo

If you have set your paths correctly (set path=/usr/include,.,../include or similar, so that they include all your headers) you can use [i to see the declaration of a variable, and CTRL-W i to go to the declaration in a new window with the original Vim parsing (without the tags).

Now that you already got tagging working, add set tags=~/.vim/stdtags,./tags,../tags,tags to your vimrc file, then create the tags, putting the tag file in one of the previously mentioned positions (for example, ./tags or ../tags). Then in the vimrc add autocmd FileType c set omnifunc=ccomplete#Complete to bind the file type with the omnifunction to use. Finally, just declare an object and try to access its members, if you are using gvim a popup will appear with the members.

Omni requires ctags to work (adding all the ctags code into the Vim executable would be a waste of time). However, it natively supports CSS and other types. Check :help ft-c-omni for more information.

(Edited: Maybe this old guide helps you?)

bamccaig
[bamccaig@rufus ~]$ du -h ~/.vim/systags 
702M	/home/bamccaig/.vim/systags
[bamccaig@rufus ~]$ 

What do I do about this? :'( I hit i CTRL-X CTRL-O and Vim locked up the entire system. :P

Thomas Fjellstrom

You probably have a shit load of dev packages installed :D

bamccaig

I removed ~/.vim/systags from the list for now because clearly it's unreasonably large. I just tried to open project specific intellisense though and I get "unknown function ccomplete"... :( Something is clearly wrong and I'm too tired to figure it out right now.

ReyBrujo

Do a <i>du -h usr/include to weight the directory. I got around 50mb, which generates a 75mb systags file. You probably passed too many arguments to ctags, generating a lot of information (that may not be necessary).

(Edited:

bamccaig said:

I just tried to open project specific intellisense though and I get "unknown function ccomplete"

Which version are you using? It looks you are missing ccomplete.vim. Try locate ccomplete to see if you have it somewhere, I had it at /usr/share/vim/vim72/autoload/ccomplete.vim.)

bamccaig
ReyBrujo said:

Do a du -h usr/include to weight the directory. I got around 50mb, which generates a 75mb systags file. You probably passed too many arguments to ctags, generating a lot of information (that may not be necessary).

148M.

ReyBrujo said:

Which version are you using? It looks you are missing ccomplete.vim. Try locate ccomplete to see if you have it somewhere, I had it at /usr/share/vim/vim72/autoload/ccomplete.vim.)

Same.

BAF

Guh, I simply do not understand the use of spaces for indenting. At all. Any proper editor should be able to emulate spaces/set whatever spacing you want/etc for tabs. Using spaces forces your shitty indentation styles on others, makes file sizes larger (negligible though), etc. And if python benefits from using spaces vs. tabs, then it's a shitty language.

ReyBrujo
Quote:

148M.

Then yeah, it is possible. Maybe you can only parse the directories you want (say, don't go into subdirectories you don't need).

bamccaig said:

Same.

What are the contents of your vimrc?

bamccaig
BAF said:

Guh, I simply do not understand the use of spaces for indenting. At all. Any proper editor should be able to emulate spaces/set whatever spacing you want/etc for tabs. Using spaces forces your shitty indentation styles on others, makes file sizes larger (negligible though), etc.

Technically, there's no reason a powerful editor couldn't also switch between space-based indentation. You should be able to say "This file was created with 4-space based indentation. Convert them to tabs."

I used to agree with tabs (and really the difference in indentation width sort of scares me about using spaces, though it should still be convertible most of the time), but I have just found tabs to be disorganized when it comes to alignment. Sure, you can use tabs to indent and spaces to align, but in practice I've found it insufficient. I'm hoping spaces corrects that problem. I don't dislike tabs, but I'm hoping moving to entirely spaces will be more organized and portable.

BAF said:

And if python benefits from using spaces vs. tabs, then it's a shitty language.

I don't even remember why spaces are recommended (though not required) for indentation in Python, but I remember accepting it as best practice. The interpreter even has command-line arguments to warn (-t) or even error (-tt) when tabs are used for indentation. Python is by no means my favorite language, though I appreciate its differences.

ReyBrujo said:

What are the contents of your vimrc?

[bamccaig@rufus trunk]$ cat ~/.vimrc
:set autoindent
:set expandtab
:set hidden
:set ignorecase
:set nowrap
:set number
:set ruler
:set shiftwidth=4
:set softtabstop=4
:set tabstop=4
":set tags+=~/.vim/systags,~/.vim/tags,../tags,./tags
:set tags+=../tags,./tags

:autocmd FileType c set omnifunc=ccomplete
:autocmd FileType cpp set omnifunc=cppcomplete
:autocmd FileType cs set omnifunc=cscomplete
:autocmd FileType css set omnifunc=csscomplete
:autocmd FileType d set omnifunc=dcomplete
:autocmd FileType javascript set omnifunc=javascriptcomplete
:autocmd FileType php set omnifunc=phpcomplete
:autocmd FileType python set omnifunc=pythoncomplete
:autocmd FileType xml set omnifunc=xmlcomplete
:autocmd FileType xsl set omnifunc=xslcomplete

"set term=ansi
"set term=color_xterm
syntax on

:colorscheme bam
":colorscheme bam-dark
[bamccaig@rufus trunk]$ 

(As you can see I may have gotten carried away with the omnifunc bits... :P Most of which I'm unsure about their correctness...)

deps

I use TextMate and two spaces. Never tabs.

Neil Walker

I see using spaces as only of relevant if the position of text in columns is important, such as tabular data. But for coding, I couldn't care less if tab is 4 characters on one computer and 8 on the other - you can still see the code layout as it was intended.

Or think of it in this way: If you use tab then you can set your preferred viewing method. If you use spaces that's all you get.

I think the pattern emerging here is those using modern IDE's use tab, and those using text based unix editors prefer spaces.

GullRaDriel

It's a lost cause. It'll always end in a war thread, between those who only think in space, and those who only thrust tabs.

My point of view on that subject is that it doesn't matter. Space and tabs are mostly ignored during compilation, and when you program something for your enterprise, only the result matters. They'll never look at your code, even if it crash.

bamccaig

Or think of it in this way: If you use tab then you can set your preferred viewing method. If you use spaces that's all you get.

While I agree with you for simple indentation, when it comes to alignment things get a little bit more complicated. Since most people have their editors configured to not show whitespace, it isn't obvious when you accidentally tab code into alignment.

--->--->really_long_function_name1(really_long_argument1,
--->--->--->                       really_long_argument2);
//      ^ Oops, that should be 4 spaces instead of a tab, but with invisible
//        whitespace you wouldn't notice.

When that code is opened in an editor whose tabstop isn't 4 the code won't line up properly anymore. It's not a show stopper (I don't have any really useful examples to show right now), but if you're obsessive about formatting like I am it's frustrating fighting with it. There's also the fact that tabs typically display as 8 characters wide in text terminals so if you spend a lot of time in them (and you should ;)) then you'll also find that spaces work better for things printed to the terminal.

I also find myself fighting with indentation in JavaScript, where I often use lots of JSON and getting it to line up properly with tabs and spaces combined is often a struggle.

I think the pattern emerging here is those using modern IDE's use tab, and those using text based unix editors prefer spaces.

I use both (I develop with Visual Studio at j0rb), but I prefer working in text terminals. Even at work though (as I said, with JavaScript, for example) I still struggle to keep alignment right.

Thomas Harte

It's a lost cause. It'll always end in a war thread, between those who only think in space, and those who only thrust tabs.

My point of view on that subject is that it doesn't matter.

But how do you feel about Hungarian Notation? Or, ummmm, Windows versus Mac? Z80 or 6502? Coke or Pepsi? Jalapenoes or chillis? Winston or Salem? Marmite or absolutely any other spread?

EDIT:

bamccaig said:

if you're obsessive about formatting like I am it's frustrating fighting with it

My only obsession, which I've been trying desperately to fight for years, is that I hate otherwise completely empty lines that have white space on them. One of my standard brain unengaged tasks when I'm thinking about a real problem is to go through source files and kill them by hand. I don't know why.

bamccaig

My only obsession, which I've been trying desperately to fight for years, is that I hate otherwise completely empty lines that have white space on them. One of my standard brain unengaged tasks when I'm thinking about a real problem is to go through source files and kill them by hand. I don't know why.

Yeah, that bothers me too. Another gripe is trailing whitespace. Fortunately, with a powerful editor it's relatively easy to get rid of both automatically.

:%s/\s\+$//g

Obviously not unique to Vim, though I would say that of the editors that I use regularly it's easiest to do in Vim. I think Visual Studio used to do this automatically, but recent iterations don't seem to have that feature by default anymore.

Thomas Harte
bamccaig said:

Fortunately, with a powerful editor it's relatively easy to get rid of both automatically.

Yeah, I know. But I like to occupy myself with a mindless task when I'm trying to think, so I prefer to do it myself. Or, at least, leave it to be done when next I have an actually hard problem rather than the routine nothingness that is 95% of all programming. In any language.

bamccaig

Mmmmmz, automatic. :P

func! DeleteTrailingWS()
  exe "normal mz"
  %s/\s\+$//ge
  exe "normal `z"
endfunc

autocmd BufWrite * :call DeleteTrailingWS()

[1]

ReyBrujo

My only obsession, which I've been trying desperately to fight for years, is that I hate otherwise completely empty lines that have white space on them.

My only one is deleting the lonely { after opening a block or function. Poor {, don't you see it is sad there alone?

Thomas Harte

So you prefer:

if(a){

to:

if(a)
{

then? Because you know you shouldn't just delete the opening curly braces?

ReyBrujo

Snap, that is why it didn't compile! :P

Neil Walker

I just wish for a day when we live in a equal and happy world that can have a standard for newlines across systems (\r\n or \n).

bamccaig

That would be an interesting compulsion. Broken code. Your team would be committing working code to the repository and you'd be breaking it syntactically and committing that. :P

Thomas Fjellstrom

My only obsession, which I've been trying desperately to fight for years, is that I hate otherwise completely empty lines that have white space on them. One of my standard brain unengaged tasks when I'm thinking about a real problem is to go through source files and kill them by hand. I don't know why.

Kate has a check box to enable the auto removal of such things on save.

Mind you I couldn't use it when I was working on allegro, it messed up the patches too much ::)

Matthew Leverton

I thought this would be about Windows Live Spaces.

GullRaDriel

The owner of allegro.cc just derailed a thread in his own forum. I just can't think that is the first time he use that technique.

;D

Neil Walker

I agree GullRaDriel. I vote we veto allegro.cc and hang out at the sdl website.

Thread #601348. Printed from Allegro.cc