Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply syntax file for vim?

Tags:

c++

vim

I've read vim manual pages and also bunch of tutorials and managed to set up my C++ environment in vim, but to apply a syntax file is probably a science fiction.

I downloaded a 'cpp.vim' which is a syntax file, now how do I apply that file so my code start shining??

I tried to place a file into following directories:

~/.vim/after/syntax/

~/.vim/syntax

/usr/share/vim/vim73/syntax (but under different name, so not replacing old file)

none of that work, and anyway if I place a file into $VIMRUNTIME/syntax under some crazy name, then how do i apply it into vim?

Here is my .vimrc setting:

"
" vim settings
"

set t_Co=256
set nocompatible
set laststatus=2

"set ruler
"set ballooneval
"set balloondelay=400
"set balloonexpr=""


filetype off


"
" vundle settings and plugins
"


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

"Vundle Plugin manager
Plugin 'gmarik/Vundle.vim' "vundle plugin manager

"Core plugins
Plugin 'ervandew/supertab' "completition with tab
Plugin 'scrooloose/syntastic' "error checking
Plugin 'vim-scripts/OmniCppComplete' "auto complete
"Plugin 'octol/vim-cpp-enhanced-highlight' "syntax highlighting
Plugin 'vim-scripts/Cpp11-Syntax-Support'
Plugin 'bling/vim-airline' "statusline and tabline

"Sipet plugins
Plugin 'MarcWeber/vim-addon-mw-utils' "required by snipmate
Plugin 'tomtom/tlib_vim' "required by snipmate
Plugin 'garbas/vim-snipmate' "insert snipets
Plugin 'honza/vim-snippets' "optional snipets


Plugin 'vim-scripts/a.vim' "Switching between source and header file
Plugin 'chazy/cscope_maps' "Allows searching code
Plugin 'vim-scripts/argtextobj.vim' "Text-object like motion for arguments
Plugin 'wincent/Command-T' "Fast file navigation
Plugin 'vim-scripts/taglist.vim' "Source code browser (requires exuberant-ctags > apt-get install)


Plugin 'ddollar/nerdcommenter' "wrangle your code comments, regardless of filetype
Plugin 'scrooloose/nerdtree' "explore your filesystem and to open files and directories
Plugin 'tpope/vim-unimpaired' "provides a lot of useful mappings
Plugin 'majutsushi/tagbar' "browsing the tags of source code files
Plugin 'chrisbra/NrrwRgn' "focussing on a region and making the rest inaccessible
Plugin 'vim-scripts/ZoomWin' "zoom into a window and out again
Plugin 'terryma/vim-multiple-cursors'
Plugin 'jeetsukumaran/vim-buffergator' "listing,navigating, and selecting buffers for edit
Plugin 'bronson/vim-trailing-whitespace' "causes all trailing whitespace to be highlighted in red

Plugin 'mileszs/ack.vim' "uses ack to search inside the current directory for a pattern
Plugin 'myusuf3/numbers.vim' "intelligently toggling line numbers
Plugin 'Lokaltog/vim-easymotion' "provides a much simpler way to use some motions in vim

call vundle#end()
filetype plugin indent on


"
" ariline options
"

let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'



"
" syntastic settings
"

let g:syntastic_enable_signs = 1
let g:syntastic_cpp_checkers = ['gcc']

let g:syntastic_auto_jump = 1
let g:syntastic_enable_balloons = 1

let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = '-std=c++11'


let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_auto_refresh_includes = 1


let g:syntastic_always_populate_loc_list = 1

syntax on
colorscheme slate

... etc

other options are plugins and plugin settings..

The Question is simple, how do I apply a syntax file ??

like image 333
codekiddy Avatar asked Mar 20 '23 04:03

codekiddy


2 Answers

All you need to do is make sure the filetype is loaded properly. So if the syntax file is called cpp.vim make sure set ft? returns cpp. You should place it in $HOME/.vim/syntax. It should get loaded automatically. Assuming filetype on and syntax on is set.

The only way to make sure the syntax file isn't loaded properly is to use :scriptnames. Make sure the file isn't listed if it is your problem is something different then what you have described.

like image 110
FDinoff Avatar answered Apr 02 '23 08:04

FDinoff


Ok, I managed to get things work :)

I downloaded two syntax files, one of which does do the job by highlighting the code and other which for some unknown reason does not.

The fact that I have Vundle installed as a plugin manager there was no need to place a syntax file anywhere because that part handles Vundle it self...

All I had to do is is to remove the syntax file that does not work. and also make several tests to see the difference between default syntax highlighting and custom with file.

to enable syntax highlighting only one option is needed placed anywhere in the .vimrc file:

syntax on

or

syntax enable

difference between these two is that 'on' switch does search for first cpp file it find inside $VIMRUNTIME directory while enable switch searches in .vim directory too. more info about that here

To make syntax highlighting more 'nice' I also downloaded color schemes which makes code much more readable. And if you just want to know how to apply that piece of file here is how: Download it with Vundle and place this at the end of your .vimrc file:

colorscheme molokai

Where molokai is the name of colorscheme downloaded with Vundle :D

YES!!!

thanks you FDinoff for trying to help! you were right about :scriptnames which actually helped me to figure out that my file isn't loaded ;)

like image 41
codekiddy Avatar answered Apr 02 '23 07:04

codekiddy