4

I like my tabs displayed as 4 spaces, and for that I have the preference core.pager = 'less -x4'.

I know that at this point I'm nitpicking, but I'd love for the leading tab to be 4 spaces even in diff mode, which is obviously the most commonly used -- however it displays as only 3 due to the leading +, -, or . This is slightly annoying due to aligned lines, if some have no leading tabs they are shifted by 1 column compared to the others.

I can correct the display for diffs with less -x1,5 to get 4-space tabs, aligned on the column 1 modulo 4. However this option then causes the leading tab to be displayed as 1 column in non-diff mode, which in turn is highly disturbing.

So for two concrete examples, how can I set git options such that I use:

  • less -x1,5 for a diff (or really patch-displaying) command such as git diff or git show HEAD
  • less -x4 for a command that does not display a diff such as git show HEAD~1:package.json

I'm sure there has to be a different renderer for what are basically diff and cat operations, but I haven't been able to find specific options for those (though they might exist, there's a lot of noise on git topics). I don't want to write a whole lot of aliases either, that's a little too dirty. So is this even possible?

Cimbali
  • 11,012
  • 1
  • 39
  • 68
  • The usual approach to solve this is to avoid hard-tabs at all: set your editor to use 4-space "soft" tabs, type the tab key, and you get spaces that everyone agrees how to format. That's the best answer I've ever found to the constant tab-vs-space war, even if it's not all that satisfactory. – torek Jan 09 '19 at 14:53
  • @torek Well git has some tab-whitespace awareness, I was hoping maybe it could do the tab expansion using the [whitespace.tabwidth](https://git-scm.com/docs/git-config#git-config-corewhitespace) option or some trick like that. After all it already does the colouring of the output. – Cimbali Jan 09 '19 at 15:56

1 Answers1

7

pager.<cmd> allows to set pager for a command:

git config [--global] pager.diff "less -x1,5"
git config [--global] pager.show "less -x4"
phd
  • 82,685
  • 13
  • 120
  • 165
  • That's pretty good, especially for such an easy solution. Ideally I would have liked for some `show` commands to behave differently, based on whether they show a patch or a file. – Cimbali Jan 09 '19 at 14:34
  • 2
    @Cimbali: you can't quite get that, unfortunately. You could make yourself an alias, `git showfile` or some such, that runs `!git --config pager.show= show`. – torek Jan 09 '19 at 14:51