Repository navigation
|
I was checking out bat to use for syntax highlighting for less (or potentially to replace less for me) and I noticed that despite telling it to use the plain style, no decorations, just do syntax highlighting, that it still inserts a space at the beginning of each line...is there any way to make it NOT do that? If using it like "cat" I see that it doesn't do that, so feels like it should be possible and maybe I'm just missing something... Thanks. |
Replies: 3 comments
|
You can keep syntax highlighting with decorations and paging disabled: bat --no-config --style=plain --color=always --paging=never file.pyI checked bat 0.26.1 with forced color and plain style: after removing the ANSI color sequences, the output had no extra leading spaces. So plain style itself doesn't require a one-column margin. If the command above removes the space on your machine, check the pager separately. In particular, LESS= bat --no-config --style=plain --color=always \
--paging=always --pager='less -R' file.pyThat's a diagnostic possibility, not something I can confirm from the description alone. If the space remains even with The pager documentation explains the separate pager settings. |
|
The decisive test is bat --no-config --style=plain --color=never --paging=never file.py | cat -A | headIf lines start immediately with no leading space before the echo "LESS=$LESS BAT_PAGER=$BAT_PAGER PAGER=$PAGER"
LESS= bat --no-config --style=plain --color=always --paging=always --pager='less -R' file.pyIf the space survives even |
|
Finally circled back to this and not sure what I was doing differently previously as I thought it was more or less the way you guys described above, but testing today w/ what you both suggested in my LESSOPEN indeed the space is gone... Not sure what the difference in what I was attempting previously and the above is, because for some reason I didn't put the LESSOPEN I was trying in my question here, didn't make a note of it or save it off anywhere either, and my history merging seems to have discarded it too, but it's definitely working more like expected now. 🤪 Thanks! |
The decisive test is
--paging=neverplus a byte-level look.plainitself adds no margin - if the space disappears below, it comes from the pager, not bat:If lines start immediately with no leading space before the
$line-end markers, bat is clean and the column is added downstream. The classic culprit isless -J/--status-column, which reserves a left column and can sneak in viaLESS,BAT_PAGER, orPAGERindependently of bat's style. Check with:If the space surv…