vim-ai
vim-ai copied to clipboard
offer markdown highlighting in aichat files
Markdown highlighting within aichat files is controlled by a global variable g:aichat_markdown.
The Vim documentation and the syntax file for aichat have been updated. Markdown highlighting is disabled by default when editing .aichat files, but can be enabled by a user variable.
What is the motivation behind this feature? Enabling full markdown got into conflict with the current aichat file highlighting:
The output is often markdown with code in codeblock. For highlighting, including codeblocks, just reuse that of markdown.vim and add the vim-ai specificities (for prompt markers).
Is in the screenshot code_syntax_enabled = 1 set ?
Yes, the screenshot is taken with code_syntax_enabled = 1. To problem is that markdown is applied to the whole file, not just to the fenced replies.
Yes. What is the correct syntax highlighting for the user input?
One could explicitly override it, but in practice it is often simple text.
This is just a suggestion that seems more maintainable than the ftplugin/aichat.vim with the added benefit of highlighting the markdown output itself (and not only the code blocks).
Regarding the correct highlighting of the user input, an idea could have been to add code fence markers for the current file type, except for text selected in a comment syntax region. However, in the end, users might rather (ab)use the source code file as a scratchpad for sending text into the chat, so that this assumption is perhaps a bit patronizing.
I am not sure is syntax highlighting of the user input is needed. If you for instance use ChatGPT on web, you cannot use formatting your prompt. And it wouldn't make any difference to the model too. I would say formatting code blocks should be enough but I might be wrong
I am not sure is syntax highlighting of the user input is needed.
I agree with you. Markdown highlighting was meant to highlight the output, not input, since the output is often markdown. One can define a user input region to drop syntax highlighting there.
User input is now using default highlighting, whereas the output uses built-in markdown highlighting, in particular for the fenced code blocks.
Since (ChatGPT's) output often uses markdown formatting, this (if g:aichat_markdown is set) improves readability and adds highlighting for programming languages not contained in s:filetype_dict in ftplugin/aichat.vim (line 12):
in contrast to
Still having the same issue (see screenshot in the comments above). I think you tried to fix it with >>> <<<, that that' boundary isn't respected in my environment
This is somewhat to be expected, as I had the impression that code_syntax_enabled = 1 replicates what g:markdown_fenced_languages= ['cpp', 'vim', 'sh', 'dosini', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact'] would achieve, and therefore becomes dispensable. But I might be completely wrong, as I rarely used fenced highlighting, and there's a point in making both settings work at the same time?
Yes, I think that this solution is much better and I would like to replace the current highlighting with this one. But first I need to get this working. I have found that there is a conflict with the plugin preservim/vim-markdown that I use, which causes the weird highlighting I posted in the screenshot.
Hard to say from afar, but https://github.com/preservim/vim-markdown/blob/a657e697376909c41475a686eeef7fc7a4972d94/ftplugin/markdown.vim#L789 shows that this also does what the built-in markdown ftplugin tries to achieve, so a careful setup is needed to avoid mutual interference
Maybe this way around the highlighting is more robust?
I came here wanting to do the same thing, thanks for your diff it works flawlessly for me !