Nick Gravgaard

nickgravgaard.com · Personal blog · on HN since 2008

Nick Gravgaard, a programmer, writes about elastic tabstops for aligning code and about proportional versus monospaced programming fonts.

What HN saysCommenters repeatedly cite his elastic tabstops as the best way to align text with proportional fonts, though they note weak editor support and formatting problems for non-users.
59HN people shared it
45linked it in comments
19stories submitted
350story points
1 year agolast shared
2008people per year2026

Most-shared posts

  1. 1
  2. 2
    Elastic Tab Stops: A Better Way to Indent and Align Code
    19 people · 84 points · first shared 2008 · 40 comments on HN
  3. 3
    Programming fonts: proportional vs monospaced
    1 people · 4 points · first shared 2012 · 1 comments on HN
  4. 4
    Programming fonts - proportional vs monospaced
    1 people · 2 points · first shared 2009 · discussion on HN
  5. 5
  6. 6
    A better way to indent and align (Swift) code
    1 people · 1 points · first shared 2016 · discussion on HN
  7. 7
    Columnblocks coloured.gif
    1 people · first shared 2018

What HN people wrote when they linked it

kragen · 2025-05-21
I think I've said this to you before, but in case I haven't, I suspect that the best way to handle proportional text in formattable plain text is some variant of Nick Gravgaard's "elastic tabstops" https://nickgravgaard.com/elastic-tabstops/: > Each cell ends with a tab character. A column block is a run of uninterrupted vertically adjacent cells. A column block is as wide as the widest piece of text in the cells it contains or a minimum width (plus padding). Text outside column blocks is ignored [for layout, though it is displayed]. I think the main deficiency in his proposal is that he enforces a minimum of one space of whitespace padding on the right of his column.
teddyh · 2019-01-21
I would suggest that using elastic tabstops¹ is the only reasonable system for doing that. Sadly, the industry seems to be stuck in a local maxima where the simultaneous jump to both using proportional fonts (which would be better) and using elastic tabstops for alignment (which would be easier), constitutes too large of a distance to bridge in a single leap, and either one by itself isn’t worth the effort. Of course, if you already have made one of these two jumps, it should be a no-brainer to make the other one as well. 1. http://nickgravgaard.com/elastic-tabstops/
armagon · 2017-07-21
It isn't quite what you asked for -- doing this automatically would be really neat -- but the best solution I've seen is called Elastic Tabstops. http://nickgravgaard.com/elastic-tabstops/ I really, really wish this was available in the editor I fight with every day.
qznc · 2016-11-06
Proportional fonts + elastic tab stops [0]. I would love to have this working. Unfortunately, if you really depend on elastic tab stops you break the formatting for everybody who does not use it. [0] http://nickgravgaard.com/elastic-tabstops/
geofft · 2016-05-17
You might like the "elastic tabstops" idea: http://nickgravgaard.com/elastic-tabstops/ Although the editor support for the concept doesn't look great.
Bognar · 2016-03-01
Elastic tabstops are clearly the best, but until we have good editor support I'm sticking with spaces. http://nickgravgaard.com/elastic-tabstops/
leeoniya · 2015-02-22
i think JSONH [1] is a great replacement for csv. it's not as human-readable, but since no editors support elastic tabstops [2] by default, most csvs aren't readable anyhow. [1] https://github.com/WebReflection/JSONH [2] http://nickgravgaard.com/elastictabstops/
saidajigumi · 2014-08-15
> Still perpetually disappointed every new "neo terminal" is monospace tho. Have you thought of ways around the path dependence[1] on monospace imposed by existing bodies of textmode UIs (and source code)? It seems unlikely that a new terminal-esque tool would succeed without some kind of legacy support. The best concept I've come up so far with is to build in affordances which handle legacy vs. new-world user interaction and app I/O models. Related, I continue to hold out (vain) hope that elastic tabstops[2] will someday gain traction. [1] https://en.wikipedia.org/wiki/Path_dependence [2] http://nickgravgaard.com/elastictabstops/
jameshart · 2014-08-13
Elastic Tabstops[1] are the solution, but support is too patchy, and getting a team to agree on tabs vs spaces for line indents is hard enough, without then getting them to all follow elastic tab practices for laying out aligned content. [1] http://nickgravgaard.com/elastictabstops/
drivingmenuts · 2014-08-04
This (http://nickgravgaard.com/elastictabstops/) is smart tab handling. All other editor aren't that great, compared to this.
Silhouette · 2014-05-24
Elastic tabstops[1] are one of those things I wish was standard in the programming world, because it seems to have essentially no downside as long as tools support it. Failing that, many text editors will provide some sort of realign command that will adjust spaces on adjacent lines so the columns line up as intended in these situations, and many diff tools and related functions like 'blame' commands in VCSes will allow you to ignore whitespace-only changes these days. Personally, I prefer to have non-trivial code neatly lined up, despite the potential irritations when reviewing changes later. I find the advantages of highlighting patterns (and highlighting where a line didn't follow the same pattern as all the others) outweigh any practical issues where a few tools show diffs I would prefer to ignore. I make an exception for Python, because PEP8 explicitly advises not to do this, and sometimes having a coding style that is consistent with everyone else is worth more than any of the above. [1] http://nickgravgaard.com/elastictabstops/
dexen · 2011-05-25
I don't follow you -- `easier scanning of indentation levels'? With proportional font, the left-hand whitespace used for indentation of your code looks exactly as with monospaced font. Only the text itself changes somewhat. The width of tab/positions of tabstops has nothing to do with font itself; it's property (often settable) of the editor (or in rare case of the underlying terminal). May be expressed as `times the space width', but that's it. Perhaps you mean aligning of function argument and/or parameters one below another, or indentation of parts of expressions one below another? That indeed can't work with proportional font IF the peers in your project use different font (size or shape) or tab-stop setting. Can't work with monospaced font either -- again, IF the peers on your project use different tab-stop settings. Which is prevalent, AFAIK. Some use 12'' netbooks, other use 23'' desktops. I've even known a guy who used a T221 [1]. One size does not fit all. Nb., you may want to read up on http://nickgravgaard.com/elastictabstops/ if you like to align stuff that way. I don't like that idea though. ---- [1] http://en.wikipedia.org/wiki/T221
matj1 · 2023-11-14
I agree with that many present tools expect character grid, but moving away from character grid would be not as much work as it seems IMO. Code can be aligned with elastic tabstops ( https://nickgravgaard.com/elastic-tabstops/ ) or virtual formatting (that things are aligned according to syntax regardless of whitespace). Things to align in terminals are mostly tables, and they could be rendered as tables if the terminal supporting that knew that they are tables. Nushell natively supports tabular data structures, so rendering them as proper tables would need just one change – the table renderer.
fanf2 · 2023-10-12
Elastic tab stops would be the Right Thing if they were implemented anywhere at all https://nickgravgaard.com/elastic-tabstops/
rhn_mk1 · 2023-07-30
You get in trouble only if you see hanging indentations: Foo(Bar(...), baz) But they are not required for a happy life: Foo( Bar(...), baz, ) It's not PEP8, but it works, and it does not depend on the font at all. 80 columns is bollocks in any case, but with this style, width is usually even reduced. Alternatively, Elastic Tabstops solves this, but it's supported by approximately no one. https://nickgravgaard.com/elastic-tabstops/
archseer · 2022-11-07
I think you mean elastic tab stops https://nickgravgaard.com/elastic-tabstops/
LanternLight83 · 2022-11-03
I used to tout "tabs for indentation, spaces for alignment" until I started working primarily woth lisps. Idiomatic lisp indention isn't compatible with regular tab-stops, so the only solution is to go with spaces (maybe losing accessability) or, preferably, to go elastic. https://nickgravgaard.com/elastic-tabstops/
warpech · 2021-07-28
That would be possible using a proportional font like Input Sans with elastic tabstops[0] [0] https://nickgravgaard.com/elastic-tabstops/
Symbiote · 2021-05-20
Elastic Tabstops is similar to what you propose, but using tab characters to form the tables: https://nickgravgaard.com/elastic-tabstops/#solution But it's 15 years since that was proposed.
nerdponx · 2021-03-31
I'll only consider using a non-monospaced font for code if elastic tabstops [0] become commonplace. [0]: https://nickgravgaard.com/elastic-tabstops/
Izkata · 2020-12-05
I believe you'd like elastic tabstops: http://nickgravgaard.com/elastic-tabstops/
vthriller · 2020-02-05
Or you could use regular tab stop characters to align parts of adjacent lines. That's the idea behind elastic tabstops: http://nickgravgaard.com/elastic-tabstops/ Not all editors, however, support this style of alignment, even if they support plugins (looks at vim and its forks).
_ZeD_ · 2019-07-08
I cannot suggest enough to avoid this debate and pass to elastic tabstops http://nickgravgaard.com/elastic-tabstops/
Ajedi32 · 2018-07-30
The first GIF in the article clearly shows how that case would be handled: http://nickgravgaard.com/elastic-tabstops/images/columnblocks_coloured… The red section in that GIF is analogous to your example.
RobertRoberts · 2018-04-17
I recently found the answer for this. Sublime [0] with the Elastic Tabs[1] plugin[2]. [0] https://www.sublimetext.com/ [1] http://nickgravgaard.com/elastic-tabstops/ [2] https://github.com/SublimeText/ElasticTabstops
martin-t · 2018-04-17
Tabs for indentation, spaces for alignment. You wouldn't need to customize anything, it would look good at all tab widths and people who prefer 2 space sized indents would be able to use that in their editors. Actually, it could be even better, we could use tabs for aligning to tables too if editors supported elastic tabstops [0]. Unfortunately, the only ones that do don't support other essential features like saving when they lose focus. Please note that i disagree with how the example aligns function params. The space/tab there looks bad and params should be aligned with spaces using a formatting tool (which every sane language should have). Or, y'know, scratch that, why don't we commit the AST (enhanced to include comments and other hints like blank lines) to git and let everyone use their formatting. </rant> [0]: http://nickgravgaard.com/elastic-tabstops/
shagie · 2017-07-21
Alas, if only tabs realized columns could occur in locations other than 8 or 4 space tab stops. http://nickgravgaard.com/elastic-tabstops/
bryanlarsen · 2016-05-30
I wish the answer was elastic-tabstops http://nickgravgaard.com/elastic-tabstops/ But compatibility trumps awesomeness, so spaces.
aubergene · 2016-01-25
I agree, particularly with Elastic Tabstops http://nickgravgaard.com/elastic-tabstops/
1wd · 2015-11-09
It's called elastic tabstops. [1] The page links some editors that implement this and some plugins for other editors. Apparently SublimeText's plugin is incorrect though. It does not mention Atom, but it was discussed in [2]. [1] http://nickgravgaard.com/elastic-tabstops/ [2] https://discuss.atom.io/t/elastic-tabstops/16/23

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close