2

I am a system administrator and not a programmer. I frequently su to different system users for task so a .vimrc file for each system user is cumbersome. I need to be able to read the comments in config files and VIM syntax highlighting gets in the way for me.

How does one globally turn off syntax highlighting in VIM on Ubuntu systems?

  • 1
    you might want to change the colourscheme instead of turning syntax highlighting off. I use the elflord colourscheme and the config gets distributed in /etc/vimrc automatically. – natxo asenjo Apr 14 '18 at 6:21
4

The downside of using a .vimrc however is, as long as you aren't using a central home directory that is mounted via NFS on all your hosts, you have to do this on every host you work on.

There is another option: vim also takes settings from environment variables.

This becomes interesting along with another tidbit that is not so widely known: SSH clients can set environment variables on the host you connect to.

On Unix/Linux you can configure this in ~/.ssh/environment:

VIMINIT=syntax off

If you are using PuTTy on Windows there is also a way to set environment variables:

enter image description here

(Don't forget to save this to your default settings.)

With this setting the SSH client will set the environment variable on the host when you connect (if the host permits it), vim will read the variable on startup and use it as a configuration.

Sadly this will not work out of the box since SSH daemons are usally configured to accept only very few environment variables from the client. A default configuration from Ubuntu looks like this:

AcceptEnv LANG LC_*

It only allows the variable LANG and all variables that start with LC_, allowing you to set the language of the output regardless on what language is configured as default on the server. To allow the vim configuration variables you have to extend this:

AcceptEnv LANG LC_* VIMINT

Of course, this will have to be done again once on every server you work on, but if you are using a configuration management environment like ansible, puppet or such this can be deployed easily and everybody working on the servers can benefit from it.

You see, there are various ways to do this, what's the best way to do it depends on your environment.

1

I think you probably don’t need to disable syntax highlighting, the issue is mainly that the default theme colors make comments too hard to read...

I would try to solve the UI issue as in general syntax highlighting will improve your productivity IMHO.

One of the more annoying things with terminal applications (xterm has the same issue) is that by default dark-blue is too dark to be visible on a black background. Not only is this frustrating, it makes the experience for new users so bad that they prefer to disable colours (or hate the ls colour output or syntax highlighting in vim).

So if you are like me, go to PuTTY Category: Window > Colours and select ANSI Blue in the Select a colour to adjust to Red:74 Green:74 Blue:255.
I do the same for ANSI Blue Bold to Red:140 Green:140 Blue:255.

http://dag.wiee.rs/blog/content/improving-putty-settings-on-windows

The advantage of that is you don’t need to adjust anything on the servers you access. A simple change on your workstation alone and maximum return.

Other terminal emulators will usually also allow you to adjust the color scheme.

  • 1
    The default vim colors assume and work well with a light background, but AFAIK only macOS terminal defaults to a light background (and I don't understand why anybody would want a light background). – Michael Hampton Apr 14 '18 at 13:00
  • My answer on this topic reflects just my personal preference. I don't happen to like syntax highlighting. Oddity of me. – JohnA Apr 15 '18 at 19:49
  • The OP asked how to turn syntax highlighting off. You failed to answer the question. – fpmurphy Apr 16 '18 at 2:07
0

Note: this is applicable for Ubuntu and probably Debian

Edit /etc/vim/vimrc

find this line

if has("syntax")
  syntax on
endif

change to

if has("syntax")
  syntax off
endif

This will turn off syntax highlighting globally. This can be undone on a per user basis by adding a .vimrc file in user homedirs with the command syntax on

Hope this is helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.