4 ms·
Paste this line into your files: # vim: ts=2 sw=2 et :
by xpaulbettsx 16y ago
Paste this line into your files:
# vim: ts=2 sw=2 et :
- MatthewPhillips 16y agoOk... care to explain?
- deleted 16y ago[deleted]
- mdwrigh2 16y agoIt's a directive for VIM to set the tabstop to 2, the shiftwidth to 2 and to enable the expandtab option. The tabstop variable sets the ratio of tabs to spaces (in this case, one tab is equivalent to two spaces). The shiftwidth variable controls how much a line gets moved when it gets "shifted". In VIM pressing << in Normal mode on a line does a left shift. With a shiftwidth of two, it will move it over two spaces to the left. >> is right shift. There are many more ways of shifting, however. The expandtab option sets it up so that every time you hit the tab key, VIM will insert the equivalent number of spaces according to the tabstop. In this case, pressing tab will give you two spaces.
- xpaulbettsx 16y agoThis makes sure that your CoffeeScript files never end up with mixed tabs/spaces, which will result in the compiler getting confused, and your hair being pulled out from "invisible syntax errors"
- technomancy 16y agoIt's a shame that this hack is necessary; it would have been so easy for the language designer to simply declare that any tab characters used as indentation result in a syntax error, and poof: a whole class of errors simply become impossible. Don't get me wrong; I will probably reach straight for coffeescript the next time I write code that runs in a browser, but this is the one thing that cools my enthusiasm for it.
- stephth 16y agoIt's a shame that this hack is necessary; it would have been so easy for the language designer to simply declare that any tab characters used as indentation result in a syntax error then someone else would say that it's a shame that TABS aren't supported and that it would have been so easy for the language designer to support them. I'm sorry if it sounds snarky, but I find it arrogant to assume that design decisions are "easy" simply because they look easy to implement.
- technomancy 16y agohttp://www.emacswiki.org/emacs/TabsSpacesBoth http://www.emacswiki.org/emacs/TabsSpacesBoth
- stephth 16y ago... unless, the person has a comic strip to back it up. :)
- technomancy 16y agoAll that to say it seems pretty uncontroversial to say that Python and Make have shown that the problem is not necessarily with meaningful indentation itself, but with the ability to have two expressions that are visually identical with different meanings.
- djacobs 16y agoPersonal preference here, but I generally like to write the "full" version of configuration option names in my .vimrc (and when giving config advice to other Vim users), because after a month of not touching my RC file, it's easy to forget what those abbreviations stand for. (I tend to limit the shorthand versions of things to the interactive Vim commandline.)
- swaits 16y agoI'd follow it up with: gg=G:retab!<CR>
- tvon 16y agoI've been using list/listchars for a few years and have come to really like it: set listchars=tab:»·,trail:· set list That will show tabs with a little double arrow and trailing dots, and show whitespace past the end of the line with dots. Regardless, with coffee being default in Rails 3.1, I'm sure editor support will show up quickly. For the time being though, I just stumbled onto this: https://github.com/kchmck/vim-coffee-script https://github.com/kchmck/vim-coffee-script (have not tried it myself).
- mdwrigh2 16y agoI'm using the vim syntax file and plugins from vim-coffee-script and really like it so far. It even will mark trailing whitespace by highlighting it red (this is configurable as well).
- graywh 16y agoIf using 'et', it's not necessary to make 'ts' equal to 'sw'. Just make 'sts' equal to 'sw' or use 'sta'.