Howdy,
Is there a way in vim to restore the terminal's original foreground color after changing it with the ':highlight Normal' command?
For example, I'm using vim.exe 7.2 in a Windows Command Prompt. My Command Prompt has green text. When I start vim.exe, I can run the following command to change the text to red:
:highlight Normal ctermfg=red
I cannot, however, figure out how to turn the foreground color back to the original color.
Of course, in this simple example, I know the original color was green, so I could just set it back to green explicitly. In real life, though, I'm writing a vim script and need a generic solution for reverting to the original color.
I've been plowing through the vim docs for the last few hours, and have tried things like ':syntax off', ':highlight normal clear', and 'syntax reset', to no avail. There was some interesting information in the termcap section about the 't_op' variable, but I can't figure out how to use it. The only success I've had so far is quitting out of vim and allowing the Command Prompt to revert to its original color; I'd really like to be able to do this from within the same vim session.
Thanks, in advance, for any suggestions you may have.
-----[20100723 13:30]-----
Sorry for my mess of comments in response to rq. I'll try posting relevant follow-up information to the original question, instead.
On my machine (vim 7.2, Windows 7, Command Prompt) synIDattr() function returns the same value for every Normal foreground color. Consider the following: I start a new vim session in my Command Prompt, with syntax highlighting disabled, and run the following script to report the foreground color of the first character of the first line:
let numID = synID(1, 1, 1)
let numIDtrans = synIDtrans(numID)
let numFG = synIDattr(numIDtrans, "fg")
echo "synID: *" . numID . "*"
echo "synIDtrans: *" . numIDtrans . "*"
echo "synIDattr(fg): *" . numFG . "*"
in response, I get:
synID: *0*
synIDtrans: *0*
synIDattr(fg): **
Observe that there is no value returned by synIDattr(), just the literal asterisk delimiters I added.
Next, I change the Normal group foreground color:
highlight Normal ctermfg=red
When I run the same script, I get the same response - no value from synIDattr(). Note that the script does return useful information when I have syntax highlighting enabled (but at that point it's too late).
-----[20100728 16:11]-----
The 'highlight Normal ctermfg=NONE' solution worked. I'll provide a bit more context, for future reference.
My goal was to write a function and hotkey for quickly switching syntax highlighting on and off. To allow the foreground color to return to the original color after disabling syntax highlighting, I had to remove the 'highlight Normal...' command from the colorscheme file, and add two corresponding commands to the function, itself:
function! fSwitchSyntax()
if exists("g:syntax_on")
syntax off
highlight normal ctermfg=NONE <--- New command
else
syntax on
highlight normal ctermfg=white <--- New command
endif
endfunction