4

I created a Docker container based on an Opensuse 42.3 image. I'm having an issue with vim not performing any syntax highlighting in my Opensuse 42.3 container. I'm running my Docker image on an Opensuse 42.3 host. If I open a bash file from within the container and use :syntax on, nothing happens. I am using the -it flag when calling docker run, and I can see colors on the files/folders when I use ls. Sourcing a .vimrc file doesn't seem to do anything as well. My XTERM environment variable is set to 'xterm', and the file that I am looking at with vim is a bash shell script file.

I have mounted my linux home directory to the home directory on the container. What are some ways to verify or run tests to see where the source of the issue may be?

wandadars
  • 1,113
  • 4
  • 19
  • 37
  • 1
    Maybe the environment variable `TERM` is not properly set. It may help other people if you include in your question the terminal emulator and/or multiplexer you're using, as well as the output of `:echo $TERM`. You might also be interested in `:h 06.2`. Also, you might prefer `:syntax enable` to `:syntax on`. `:syntax enable` won't link a syntax item to a highlight group if it has already been done. – user852573 Aug 07 '17 at 22:58
  • I have a shell script that I source upon entry to the container that contains: export TERM=xterm. I'm not sure how to find out what emulator that I am using. I just use the terminal that comes default with OpenSuse 42.3. I also do not understand the context of ":h 06.2". What does that mean? syntax enable does not have any effect on the syntax highlighting. – wandadars Aug 08 '17 at 01:07
  • 1
    I'm voting to close this question as off-topic because there's no way to know the environment of the OP, or which ``filetype`` vim syntax color isn't working for. – Meitham Aug 08 '17 at 08:54
  • 2
    Is the colorscheme active; i.e. is there colorful output of `:hi`? If yes, there are no syntax definitions / filetype detections installed in the container. If not, check `:set t_Co?`, it's probably `2`. That's an indication of a problem with `$TERM` or the installed terminal definitions. – Ingo Karkat Aug 08 '17 at 09:13
  • @wandadars `:h 06.2` is a command that you could type on Vim's command-line. Once executed, Vim should display a page from the built-in help explaining what could cause the absence of colors. – user852573 Aug 08 '17 at 09:55
  • 1
    @Meitham, I have made edits to the post to clarify the question. – wandadars Aug 08 '17 at 15:39

2 Answers2

4

I used the :hi command with vi open, and the output was colorful. According to Ingo Karkat that meant that there were no syntax definitions/filetype detections installed in the container. I used zypper install -y vim-data, and vi started to highlight syntax in files.

wandadars
  • 1,113
  • 4
  • 19
  • 37
  • 1
    One would have to have `zypper` in order for this to work! Not every docker image will have it. – Nike Jan 09 '23 at 21:37
1

I also run into the same problem. The system I use is docker + centos7+ vim7. I solved the problem by updating vim 7 to vim 8.

xjtan
  • 127
  • 5
  • Even with vim 8.0, which is the default available in this (registry.gitlab.com/molcas/dockerfiles/gcc-4.8) docker image, there's no syntax highlighting. Upgrading beyond 8.0 with [this procedure](https://askubuntu.com/a/1001848/676348) also fails in that container with `You need to install a terminal library; for example ncurses`, so a complete solution would not be as simple as it appears from this [and this accepted answer](https://stackoverflow.com/a/45581022/1271772) which requires `zypper`, which is not available from `apt-get`. – Nike Jan 10 '23 at 01:27