Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax highlight in vim not working at all

Tags:

vim

I've just been busy configuring vim to look like an IDE with the help of this and this source, but i can't seem to get the syntax highlighting to work.

In my ~/.vimrc i have the following two settings filetype plugin indent on and syntax on that supposed to highlight the syntax, but whenever i open a file (Javascript for example) it doesn't work.

When i open the file and do :syntax list i get the following response: No syntax items defined for this buffer

I (quick) search on the internet al refer to the settings i mentioned (and are defined correctly).

What am i missing?

Below my whole .vimrc content

set nocompatible

"""" Config Vundle plugin manager """""
filetype off

set rtp=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

"""" Plugins """"
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'vim-syntastic/syntastic'
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-easytags'
Plugin 'majutsushi/tagbar'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'vim-scripts/a.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'tpope/vim-fugitive'
Plugin 'Raimondi/delimitMate'
Plugin 'jez/vim-superman'
Plugin 'christoomey/vim-tmux-navigator'
Plugin 'jez/vim-c0'
Plugin 'jez/vim-ispc'
Plugin 'kchmck/vim-coffee-script'
Plugin 'godlygeek/tabular'
Plugin 'HTML-AutoCloseTag'
Plugin 'ekalinin/Dockerfile.vim'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'tpope/vim-surround'
Plugin 'ntpeters/vim-better-whitespace'
Plugin 'edkolev/tmuxline.vim'

"""" OSX stupid backspace fix """"
set backspace=indent,eol,start

call vundle#end()
filetype plugin indent on
syntax on

"""" General settings """"
set backspace=indent,eol,start
set ruler
set number
set showcmd
set incsearch
set hlsearch

"""" Set tabs """"
set tabstop=2
set shiftwidth=2
set smarttab
set expandtab

"""" Enable mouse support """"
set mouse=a

"""" Enable highlighting of the current line """"
set cursorline

"""" Support symbols in the title bar """"
hi clear SignColumn

"""" Colorscheme (Solarized) """"
set background=dark
colorscheme solarized

" Always show statusbar
set laststatus=2

"""" Enable Menlo font """"
let g:airline_powerline_fonts = 1

" Show PASTE if in paste mode
let g:airline_detect_paste=1

" Show airline for tabs too
let g:airline#extensions#tabline#enabled = 1

" Use the solarized theme for the Airline status bar
let g:airline_theme='solarized'

"""" Nerdtree config """"
" Open/close NERDTree Tabs with \t
nmap <silent> <leader>t :NERDTreeTabsToggle<CR>
" To have NERDTree always open on startup
let g:nerdtree_tabs_open_on_console_startup = 1

"""" Scrooloose/syntastic settings """"
let g:syntastic_error_symbol = '✘'
let g:syntastic_warning_symbol = "▲"
augroup mySyntastic
  au!
  au FileType tex let b:syntastic_mode = "passive"
augroup END

"""" Easytags settings """
set tags=./tags;,~/.vimtags
" Sensible defaults
let g:easytags_events = ['BufReadPost', 'BufWritePost']
let g:easytags_async = 1
let g:easytags_dynamic_files = 2
let g:easytags_resolve_links = 1
let g:easytags_suppress_ctags_warning = 1

"""" Tagbar settings """"
" Open/close tagbar with \b
nmap <silent> <leader>b :TagbarToggle<CR>
" Open tagbar automatically whenever possible
autocmd BufEnter * nested :call tagbar#autoopen(0)

"""" Vimgutter settings """
" In vim-airline, only display "hunks" if the diff is non-zero
let g:airline#extensions#hunks#non_zero_only = 1

"""" delimitMate settings """
let delimitMate_expand_cr = 1
augroup mydelimitMate
  au!
  au FileType markdown let b:delimitMate_nesting_quotes = ["`"]
  au FileType tex let b:delimitMate_quotes = ""
  au FileType tex let b:delimitMate_matchpairs = "(:),[:],{:},`:'"
  au FileType python let b:delimitMate_nesting_quotes = ['"', "'"]
augroup END

"""" Superman config """"
noremap K :SuperMan <cword><CR>

EDIT:

Below the response of vim --version

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by [email protected]
Normal version without 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      -terminal
+builtin_terms   +fork()          +multi_lang      +terminfo
+byte_offset     -gettext         -mzscheme        +termresponse
+channel         -hangul_input    +netbeans_intg   +textobjects
+cindent         +iconv           +num64           +timers
-clientserver    +insert_expand   +packages        +title
-clipboard       +job             +path_extra      -toolbar
+cmdline_compl   +jumplist        -perl            +user_commands
+cmdline_hist    -keymap          +persistent_undo +vertsplit
+cmdline_info    +lambda          +postscript      +virtualedit
+comments        -langmap         +printer         +visual
-conceal         +libcall         -profile         +visualextra
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             -rightleft       +windows
+diff            +menu            +ruby/dyn        +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
-emacs_tags      -mouseshape      +startuptime     -xpm
+eval            -mouse_dec       +statusline      -xsmp
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard
+extra_search    -mouse_jsbterm   +syntax          -xterm_save
-farsi           -mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa

EDIT 2

I now noticed that when i try to reload my .vimrc file, i get the following error:

Error detected while processing /usr/share/vim/vim80/syntax/syntax.vim:
line   42:
E216: No such group or event: filetypedetect BufRead

Which points me in the direction of changing my runtimepath value, but i don't have that defined anywhere. I've tried adding it to my .vimrc, but i still get the same error after reloading.

I've placed it at the top of the document (right after set nocompatible, so perhaps the position could be the issue, but if so, where should i place it then?

like image 728
Maurice Avatar asked Apr 07 '18 15:04

Maurice


People also ask

How do I enable syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Does vim support syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

Why is vim highlighting in red?

vimrc was using syntax highlighting and it was a syntax error the red highlight was flagging. Fixing these solved the issue, but if that's not an option :syntax off is your go-to.


2 Answers

Damnit, i was missing a + character in line 6

set set rtp=~/.vim/bundle/Vundle.vim should have been set rtp+=~/.vim/bundle/Vundle.vim. Now it works!

like image 111
Maurice Avatar answered Oct 10 '22 04:10

Maurice


Make sure you can :source ~/.vimrc successfully with no error when you edit update ~/.vimrc.

Step to do source vimrc:

  1. vim ~/.vimrc
  2. type :source ~/.vimrc
  3. enter
like image 20
Kiet Nguyen Avatar answered Oct 10 '22 05:10

Kiet Nguyen