Original post

I've got a colorscheme configured in my .vimrc but sometimes I'd like to turn it off completely which means that I would like Vim to use the default background and foreground colors of my terminal.

My problem is that I don't know how to easily do it. When I use :syntax off Vim turns off most of its coloring but it doesn't remove the cursorline color. It doesn't change the background color to the terminal's default one.

Is there a command like :nocolorscheme or vim -u NONE but just for the colors?

I am aware of the fact that I can create a custom .vimrc file and load it with the -u option. I am looking for an easier solution though.

Major update

Because you've suggested me a number of different commands and approaches I decided to show you some photos of the screen after calling those commands.

I think you describe two different things: If you want to disable the colorscheme you will not have your terminals colors but the default colors of vim. If you want to have your terminal colors in vim you'll have to find (or create) a colorscheme matching your terminal's one.
– statox♦Jul 13 '16 at 7:37

@statox OK, I just thought that when I run vim -u NONE it inherits the terminal's defaults. Thanks for pointing that out.
– Mateusz PiotrowskiJul 13 '16 at 7:48

If only it was that easy I think a lot of people would be pretty happy ;-) But I think it is not possible for at least to reasons: 1) not all terminal define their colors the same way 2) Vim has its own color mechanism which is hardly compatible with the existing mechanisms for terminals. Now I'm really not an expert in color customization so maybe a colorscheme guru will be able to be more specific or will know a way :-)
– statox♦Jul 13 '16 at 7:51

1

I've updated my answer to account for underlining. I should have been a bit more clear in my previous comment: I understand that the t_Co setting appears to have different effects depending on your colorscheme, although I have no idea by what mechanism this might occur. One more thing to try: When using monokai, run :set t_Co=0, immediately followed by :verbose set t_Co? What is t_Co set to? (I'm wondering if somehow it's not getting set correctly: my only guesses are that possibly you've got an autocommand that resets it, or there is a bug that is causing it not to be set.)
– RichJul 20 '16 at 8:36

1

Okay, mystery solved: see my update as to why :set t_Co=0 doesn't work when the colorscheme is set to monokai.
– RichJul 22 '16 at 8:31

2 Answers
2

Disabling Colours Entirely

If you want Vim not to use colours at all, you just need to run the command:

:set t_Co=0

This tells Vim that it is running in a terminal that does not support colours, so Vim will only output black and white text (which will then be displayed by your terminal in its default colours).

However, note that after changing the t_Co setting the current colorscheme is reloaded (so that it can make appropriate changes to the colours it defines). The "monokai" colorscheme you are using starts with the line :set t_Co=256, immediately resetting the option.

I'd argue that this is incorrect behaviour, and should be filed as a bug with the maintainer of that colorscheme. Of course, they might well disagree and argue that as their colorscheme requires 256 colours, it doesn't make sense to try and use it in a terminal which does not support this (and that this line helps monokai work correctly when Vim is running in an incorrectly configured terminal).

Either way, you will need to change colorscheme away from monokai first before setting the t_Co option, as you have discovered.

Restricting Colours to Those Used Commonly in the Shell

The colours that Vim uses for its output can be defined and viewed with the :highlight command. Running :highlight clear will reset these to Vim's defaults (effectively the same as running :colorscheme defaults)

Excerpt from :help :highlight:

:hi[ghlight] clear Reset all highlighting to the defaults. Removes all
highlighting for groups added by the user!
Uses the current value of 'background' to decide which
default colors to use.

(N.B. Note the comment about the 'background' option.)

If this doesn't produce the output you desire, you have a couple of options.

If you're currently using Vim in 256-colour mode, you could try using 16-colour mode instead, as this would result in Vim selecting from the palette of colours that you are more likely to see when in the shell.

The clean way to do this is by running Vim with a different $TERM variable set. The value you need to use depends on your terminal, but, for example, if your $TERM is usually xterm-256color, then running vim with the following command will do the trick:

TERM=xterm vim

(You can also achieve a similar effect in a more hacky fashion by setting the terminal option directly inside vim: :set t_Co=16.)

Alternatively if it's only a handful of particular items that are coloured incorrectly, you could just change the colours of those items with the :highlight command. e.g. to remove the background colour from the cursor line:

:highlight CursorLine ctermbg=NONE

If you're not sure which group you need to change, you can either just run :highlight with no arguments or you can run: :so $VIMRUNTIME/syntax/hitest.vim to open a new window displaying all current highlighting.

See the sections at the bottom of this answer for tips on how to make doing this quick with a custom command or by setting up a new colorscheme.

Background Colour Erase (BCE)

If you have a problem with the background looking different when it contains text, you might be encountering BCE (Background Color Erase). You can disable this with the command:

It looks like it just sets colorscheme default. Together with syntax off it is almost what I desire. Except that (1) the cursorline is still underlining the current line and colors it white; (2) the line numbers are still colored.
– Mateusz PiotrowskiJul 13 '16 at 10:31

1

@MateuszPiotrowski I've expanded my answer somewhat, which hopefully will help. Note that unless you're turning off colours entirely, it doesn't really make sense to say that you don't want Vim to use a colorscheme. Vim displays stuff on screen, and it has to use some colours. The colours are defined by the colorscheme.
– RichJul 13 '16 at 10:59

@MateuszPiotrowski "LineNr" is the highlight setting that affect the colours of the line numbers.
– RichJul 13 '16 at 11:00

3

Actually, re-reading your question, it looks like maybe you do just want to turn off the colours entirely. :set t_Co=0 will do that for you.
– RichJul 13 '16 at 11:35

None of these options work as I expect. vim -u NONE starts with terminal's background and foreground but it doesn't load any vimrc. I wonder what should I disable to get this effect.
– Mateusz PiotrowskiJul 15 '16 at 10:12