Okay, so I'm doing this: grep "foobar" *.* | nvim -R and it works, but to get syntax highlighting I have to run :set filetype=bash or choose some other filetype that might make the grep result easier to read. Is there a filetype that works pretty well no matter the text content that is found my grep? I want something general purpose. Any ideas or alternatives?
Another idea is to use batcat instead, but Neovim is more powerful and comfortable for me to use since I know it better.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You can set the filetype in Neovim based on the input's content using the $LANG environment variable. Setting $LANG to C will force Neovim to treat the input as plain UTF-8 text, which should work well for most text contents. Here's how you can modify your command to set the $LANG variable:
In this command, LANG=C is set before running nvim to ensure that Neovim treats the input as plain UTF-8 text. The --cmd 'set ft=utf-8' option is used to set the filetype to utf-8 within Neovim, which enables syntax highlighting for most text contents.
Note that this assumes your text content is encoded in UTF-8. If your text is encoded differently, you'll need to set the appropriate encoding to ensure correct syntax highlighting.
As for using batcat, it's a good alternative when you want syntax highlighting out of the box. However, as you mentioned, Neovim is more powerful and comfortable for your workflow, and with the $LANG environment variable trick, you can achieve similar results.
If you want to stick with Neovim and have a more general-purpose syntax highlighting, you can use the plaintext filetype. This filetype is designed for displaying plain text with no syntax highlighting, but it still can provide basic highlighting for things like quotes, comments, and keywords.
This should provide a more general-purpose syntax highlighting for text contents found by grep, but it's not necessarily the most efficient way to display text with syntax highlighting for all possible contents. The best approach depends on the specific text contents you're working with and the level of customization you need.