I want to display a file in Neovim with ansi terminal escape codes interpreted.
I created a file which contains ansi escape codes (only colors for now, we can think about others as a bonus):
echo '\e[31mred\e[m other \e[32mgreen\e[m end' > file
Now if I open this file in neovim I can see and edit the escape chars but the colors are not displayed:
I know about the AnsiEsc plugin and it can do the job pretty good:
nvim file +AnsiEsc
but it misses the point about my color scheme and it is an external plugin. Also it uses syntax groups and these are limited in number and have to be defined manually by the maintainer. I am not sure if it even can interpret other stuff besides color escape codes. (Edit: I have since reimplemented an advanced version of this approach inside Nvimpager in lua. It generates the syntax groups dynamically by parsing the input file and can handle many terminal attributes (italics, bold, underline, ...) in addition to colors. But it suffers from one restriction that is also present in AnsiEsc: It can not know the correct 24bit color of the default terminal colors, so like AnsiEsc it displayes them slightly of. The code is here.)
Obviously the internal
:terminal should solve these restrictions, but if I use
:terminal cat file to view the file it adds extra text at the end and also adds extra empty lines to fill the window:
nvim '+term cat file'
:terminal of plain vim does a better job in this regard:
vim +'term ++curwin cat file'
It doesn't print extra text at the end of the command output (no message and no empty lines). But then again I want to use neovim :(
Can something as close as possible as the vim version be achieved with neovim's
EDIT: I since came half a step further: If I use
nvim '+term tail -f -n +1 file' the process never terminates (
tail -f) and hence the indicater that neovim normally prints is gone. I did not see a problem with the running tail process in my use case but it would obviously be nicer if the process was finished. That's why it is only half a step. The additional lines at the end are still there: