bat
bat copied to clipboard
Open $VISUAL / $EDITOR on "v" keypress
When using a pager app, I expect to be able to use key v as you would in more / less to invoke $EDITOR
Right now on MacOS (Ventura), doing so results in the error dialog Cannot edit standard input (press RETURN)
It would be wonderful to be able to open $EDITOR on the original file from bat in such a way; this seems the only missing feature as a great replacement for more / less, at least for files of a reasonable size e.g. source code and config files.
O cool i was just coming to say i was having this same problem with using bat. I get the same error no matter what i do Cannot edit standard input (press RETURN)
It says in SUMMARY OF LESS COMMANDS the MISCELLANEOUS COMMANDS under help that the keyboard shortcut for "v"
v Edit the current file with $VISUAL or $EDITOR.
I have tried all sorts. My $EDITOR & $VISUAL are already set to micro, I also tried tinkering with /home/greg/.config/bat/config and adding export EDITOR="micro" , or just EDITOR=micro, i have tried a few variations but i can't figure it.
❱bat --diagnostic
Software version
bat 0.24.0 (fc954685)
Operating system
Linux 6.6.5-1-MANJARO
Command-line
bat --diagnostic
Environment variables
SHELL=/bin/bash
PAGER=<not set>
LESS=<not set>
LANG=en_GB.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=most
System Config file
Could not read contents of '/etc/bat/config': No such file or directory (os error 2).
Config file
EDITOR=micro
Custom assets metadata
Could not read contents of '/home/greg/.cache/bat/metadata.yaml': No such file or directory (os error 2).
Custom assets
'/home/greg/.cache/bat' not found
Compile time information
- Profile: release
- Target triple: x86_64-unknown-linux-gnu
- Family: unix
- OS: linux
- Architecture: x86_64
- Pointer width: 64
- Endian: little
- CPU features: fxsr,sse,sse2
- Host: x86_64-unknown-linux-gnu
Less version
> less --version
less 643 (PCRE2 regular expressions)
Copyright (C) 1984-2023 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
Unfortunately, this isn't natively possible through bat. It is possible, though!
For a bit of context, the way that bat currently works is by pre-processing the source file into something that looks nice in a terminal. It then pipes this into less, so less can handle the paging aspect. As a result, less isn't given any information about the original file, nor does it provide a way for bat to do so. Because of that, it doesn’t know what file to edit or even how to ask bat for the updated contents.
Luckily, you can use bat as a preprocessor for less (similarly to lesspipe). This allows you to run less file.txt with all the bat formatting and with the ability to open an editor from the pager.
I'm currently on mobile writing this and have a final today, so I can't write up an example on the spot, but I made something for this a while back. If the lesspipe-like features are too heavy for your needs, this article provides a really small example of how you can DIY a simpler solution.
@eth-p thanks for all your hard-work!
I have been thinking about writing a patch that does exactly this. Just having searched the history, making sure I didn't create redundant threads.