2

I modified a colorscheme file which generates E419/E420 errors when loading, but I would like to ignore them silently. silent! and try/catch aren't working for me.

My .vimrc is shown below. All the loading of the "theme" is done at source ~/.vim/theme.vim.

.vimrc

set backspace=2

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set smarttab

:au FileType cpp setlocal tabstop=2 shiftwidth=2 softtabstop=2 cindent
:au FileType tcl setlocal tabstop=2 shiftwidth=2 softtabstop=2
:au FileType make setlocal noexpandtab

source ~/.vim/theme.vim                                                                                                                                                                                             

set cursorline
set hlsearch
set showmatch
set matchtime=0
syntax enable

set number
set relativenumber
nmap <F3> :set nu! rnu!<CR>

nnoremap Q <nop>

" *last-position-jump*
:au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

Attempt 1: ~/.vim/theme.vim

set t_Co=256
let g:gruvbox_termcolors=16
set background=dark
silent! colorscheme gruvbox

Using silent! I still get these errors whenever I start vim:

Error detected while processing function <SNR>3_HL:
line   43:
E419: FG color unknown
E420: BG color unknown
E420: BG color unknown
E420: BG color unknown
E419: FG color unknown
E419: FG color unknown
E419: FG color unknown
E419: FG color unknown
E419: FG color unknown
E419: FG color unknown
E419: FG color unknown
Press ENTER or type command to continue

Attempt 2: ~/.vim/theme.vim

set t_Co=256
let g:gruvbox_termcolors=16
set background=dark
try
    colorscheme gruvbox
catch
endtry

Using try/catch, I still get the same errors as above.

Attempt 3: ~/.vimrc

I also tried the same techniques directly in my ~/.vimrc, wrapping them around the source command, but I still get the same errors.

silent! source ~/.vim/theme.vim

try
    source ~/.vim/theme.vim
catch
endtry

How can I silence these errors every time I launch vim?

vim --version output

$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct  7 2016 22:47:41)
Included patches: 1-2
Compiled by ...
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
+balloon_eval    +folding         +mouse_xterm     +termguicolors
+browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     +gettext         -mzscheme        +textobjects
+channel         -hangul_input    +netbeans_intg   +timers
+cindent         +iconv           +num64           +title
+clientserver    +insert_expand   +packages        +toolbar
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        -perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  -lua             +rightleft       +writebackup
+diff            +menu            -ruby            +X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     +xpm
+emacs_tags      +mouseshape      +startuptime     +xsmp_interact
+eval            +mouse_dec       +statusline      +xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax          
+farsi           +mouse_netterm   +tag_binary   
...
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf -lnsl  -lselinux -lacl -lattr   
2

The command syntax enable reloads your current color scheme. This is documented at :help syntax-loading. If there is an error in the colors file, you'll see it then. Options:

  1. Move syntax enable to before the colorscheme statement. This makes the most sense- you should be enabling syntax highlighting before loading color schemes.

  2. Use silent! syntax enable (or try/catch).

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.