why bat can not enter edit mode?
qbai opened this issue ยท 8 comments
when I use sudo bat a.sh then enter v, I can not enter edit mode as help document described. my env variable is
echo $VISUAL
nano -m -$
echo $EDITOR
nano -m -$
the status bar show the message as following:
can not edit standard input (press enter)
please help to see this problem, thanks a lot
When bat
passes the text it outputs to your pager (i.e. less
, which provides this edit function and corresponding error message), the pager just sees standard input, it doesn't know what underlying file to open for editing.
This functionality could potentially come as part of #1053
@keith-hall
thanks your feedback.
and I am confused. when I run 'less -i -M -R -j20 -J a.sh' then click v key, it always enter edit mode. But when I run 'bat --pager="less -i -M -R -j20 -J" a.sh' then click v key, it failed as the above message.
as you described, the error message came from less, why I can use less to edit but can not use bat to edit which called less ?
is that a bug for bat that can not start less correctly?
or could you tell me if you can use bat to edit one file by clicking v key in your environment?
When you run less
directly and give it a filename, it knows what file to open in your editor.
When you call bat
, it is adding decorations, syntax highlighting etc and so passes the contents to less
via stdin, so there is no file on disk for less
to open in your editor.
is that a bug for bat that can not start less correctly?
I don't think so. You would see the same behavior with cat a.sh | less
.
Even if less
supported passing a filename reference for editing purposes, there can be situations where bat
is outputting multiple files or content piped into bat
with no single underlying file to edit.
@keith-hall
I know what you mean, but my question is what is meaning for bat with v shortkey. As bat's help description as following:
v Edit the current file with $VISUAL or $EDITOR.
that means that when you click v key, bat should call $VISUAL or $EDITOR to edit file, just like less does. but now bat actually can not edit any file, right?
so I still think this should be a bug for bat, or be a new feature as your opinion when bat open only one file.
The interactive output you see is provided by less
and not by bat
. As @keith-hall explaind, bat
passes all its output to less
for paging, but without file information. bat <file>
is roughly the same as bat --decorations=always --color=always <file> | less -rF
. bat
just calls less
automatically, so users don't have to specify explicitly. The scrolling, searching, shortcuts, etc. are all features of less
and not bat
.
#1053, which I'm currently working on an implementation for, could provide such functionality even in cases with multiple files.
@einfachIrgendwer0815
ok, as one obvious issue, I suggest to add comment on bat's readme and tell users that currently bat can not transfer filename to less that less can not call $EDITOR successfully. so now bat is crippled to edit file.
#2763 is related. This comment suggests a possible workaround.