Matchit not working - vim

I am using Macvim 7.3 snapshot 57. I can't seem to get matchit to work in any of my files.
I press % on an opening tag. It doesn't take me to the closing tag...
My vimrc file:
" Pathogen settings
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
set nocompatible
set number
set ruler
set cursorline
syntax on
" Disable all blinking
set guicursor+=a:blinkon0
" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set cindent
set smartindent
set autoindent
set list listchars=tab:\ \ ,trail:·
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Status bar
set laststatus=2
" Start without the toolbar
set guioptions-=T
" Default gui color scheme
" "color default
" color molokai
color railscasts+
" Command-/ to toggle comments
map <D-/> :TComment<CR>j
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby
" Open split buffers below instead of above current buffer
set splitbelow
" Session options
let g:session_autoload = 1
let g:session_autosave = 1
" Buffer navigation
map <C-K> <C-W><C-K>
map <C-J> <C-W><C-W>
map <C-H> <C-W><C-H>
map <C-L> <C-W><C-L>
" Rails navigation options
nmap <leader>rc :Rcontroller
nmap <leader>rv :Rview
nmap <leader>rm :Rmodel
" Tab completion
" Also needed for better Rails navigation auto-completion
set wildmode=list:longest,list:full
" Open up side panel left (NERDTree) and right(Tagbar)
" nmap <leader>\ :NERDTreeToggle<CR> :TagbarToggle<CR>
nmap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>
" Allow single click for NERDTree
let NERDTreeMouseMode = 3
let g:NERDTreeWinSize = 30
" autocmd VimEnter * NERDTree
" Tagbar options
let tagbar_singleclick = 1
let g:tagbar_sort = 0
let g:tagbar_width = 30
" autocmd VimEnter * nested TagbarOpen
" The Janus plugin sets this to noequalalways for the Zoominfo plugin
" However, we want to set this to equalalways instead, since we want to
" have equal window height when a new window is opened. i.e. via ctrl+w+s
set equalalways
" Matchit already installed in newer versions of vim.
" Don't need to add this onto pathogen bundle folder. We only need
" to configure it.
" Configure matchit so that it goes from opening tag to closing tag
au FileType html,eruby,rb,css,js,xml runtime! macros/matchit.vim
" Set backup and swp dir. Don't forget to clear tmp dir out once in a while
set backupdir=~/.vim/tmp/backup
set directory=~/.vim/tmp/swp
" Detect if a tab was closed, and ensure that height of main window fills the screen (100% height)
au TabEnter * let &lines = 100
" <leader>\ to open or close NERDTree and Tagbar, under the following conditions:
" 1) Only close both if NERDTree and Tagbar are both opened
" 2) Open both if NERDTree and Tagbar are closed OR if one is already opened
function! ToggleNERDTreeAndTagbar()
let w:jumpbacktohere = 1
" Detect which plugins are open
if exists('t:NERDTreeBufName')
let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
else
let nerdtree_open = 0
endif
let tagbar_open = bufwinnr('__Tagbar__') != -1
" Perform the appropriate action
if nerdtree_open && tagbar_open
NERDTreeClose
TagbarClose
elseif nerdtree_open
TagbarOpen
elseif tagbar_open
NERDTree
else
NERDTree
TagbarOpen
endif
" Jump back to the original window
for window in range(1, winnr('$'))
execute window . 'wincmd w'
if exists('w:jumpbacktohere')
unlet w:jumpbacktohere
break
endif
endfor
endfunction

Since Vim comes shipped with matchit plugin, all I needed to do was activate it:
vim ~/.vimrc
Then add the following into your .vimrc:
set nocompatible
filetype plugin on
runtime macros/matchit.vim

This line
runtime macros/matchit.vim
is the standard way of activating matchit and it works on all my machines.
Does matchit work after you type
:runtime macros/matchit.vim
in normal mode ?

The page of the matchit plugin says:
Make sure you have a line like
:filetype plugin on
in your vimrc file. This enables filetype plugins, many of which tell
matchit.vim which matching pairs to use.

FYI: in vim 8 runtime macros/matchit.vim becomes packadd! matchit.

I started having the same issue after I updated some of my vim plugings to the latest version for 7.3.
But when I run
:MatchDebug
it fixes the issue for me.

I had a problem with matchit finding the correct matching brace in C++/C when there were commented braces. The following steps, taken from this forum post written by this guy, solved it for me and also pretty much explained the way the whole thing works:
Create the folder ~/.vim/plugin if it is not already there:
mkdir ~/.vim/plugin
Create a file with the name
~/.vim/plugin/matchit.vim :
vi ~/.vim/plugin/matchit.vim
and the following contents:
runtime macros/matchit.vim
Create the directory ~/.vim/doc if it is not already there:
mkdir ~/.vim/doc
Copy /usr/share/vim/vim73/macros/matchit.txt to ~/.vim/doc/ :
cp /usr/share/vim/vim73/macros/matchit.txt ~/.vim/doc/
Open vi
vi
and execute the following in it:
:helptags ~/.vim/doc
Make sure that your ~/.vimrc includes one of the following:
source $VIMRUNTIME/vimrc_example.vim
or
runtime vimrc_example.vim
or
filetype plugin on
or
filetype plugin indent on
Add the following autocommand in your vimrc:
" make matchit work on C-like filetypes
" c and cpp are already handled by their ftplugin
au Filetype css,javascript
\ let b:match_words = &matchpairs
Restart Vim.

I've had similar problem. I've tried runtime macros/matchit.vim with VIM-provided script and it didn't work.
So I've downloaded this script in version 1.13.2 from http://www.vim.org/scripts/script.php?script_id=39, unzipped it into ~/vimfiles and it works!

Related

open taglist window only for c files

I want to open the taglist window only specifically for the C files
If I put the following command in my .vimrc then the window opens for all the files
let Tlist_Auto_Open=1
However, when I used autocmd based on filetype, it does not open. Is there any kind of dependency that I need to check for ?
autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1
A part of my .vimrc looks like below -
" Install pathogen
execute pathogen#infect()
set number " Display Line Numbers
set autoindent " Auto-indenting
set showmatch " Highlight Matching brackets
set tabstop=4 " Default tabstop value
set shiftwidth=4
set smarttab " Enable smart tab
set hlsearch " highlight searched items
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
" set scrolloff=999 "Start scrolling when we're 8 lines away from margins
" No annoying sound on errors
set noerrorbells
set novisualbell
set timeoutlen=500
filetype plugin on
filetype plugin indent on
set ic
autocmd filetype python set expandtab
" Remove the trailing white-spaces in the C-file
autocmd FileType c,cpp,h,py autocmd BufWritePre <buffer> %s/\s\+$//e
" Unmap the tab-key in the taglist window.
:autocmd BufEnter __Tag_List__ silent! nunmap <buffer> <Tab>
" Syntax higlight for Groovy
au BufRead,BufNewFile *.atc set filetype=groovy
""""""""""""""""""""""""""""""""""
" Taglist configuration
""""""""""""""""""""""""""""""""""
"
" To automatically close the tags tree for inactive files.
" let Tlist_File_Fold_Auto_Close = 1
" Display only one file in taglist.
let Tlist_Show_One_File = 1
" Taglist window size
let Tlist_WinWidth = 30
" Open Taglist by default
autocmd FileType c,cpp,h,py let Tlist_Auto_Open=1
" Close VIM when only taglist window is open
let Tlist_Exit_OnlyWindow = 1
This is a timing problem. The taglist plugin evaluates the Tlist_Auto_Open configuration during its load. At that point in time, your ~/.vimrc has been read, but no file has yet been opened. Your :autocmd only activates after such file has been :edited, and by then, the taglist initialization is over. Also, until you only edit one [type of] file in a Vim session, your approach would have resulted in all subsequent files opening the taglist!
So, you cannot use the taglist-provided config feature, but fortunately it is very easy to implement an automatic triggering of the plugin via the :TlistOpen command. Just modify your autocmd to this:
:autocmd FileType c,cpp,h.py TlistOpen

Slow performance on CtrlP , it doesn't work to ignore some folders

I tried to ignore the vendor by adding the following setting in .vimrc
and I start my ctrlP by typing ff
map ff :CtrlP<.><cr>
However, it still tried to index all the files under the zeus folder including vendor folder.
But after finishing index, I still can NOT search the files under vendor,
Why does CtrlP take long time to index ?
129 "add ctrlp.vim setting
130 ""
131 set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
132 let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
133 let g:ctrlp_working_path_mode = 'ra'
134 let g:ctrlp_match_window_bottom=1
135 let g:ctrlp_max_height=25
136 let g:ctrlp_match_window_reversed=0
137 let g:ctrlp_mruf_max=500
138 let g:ctrlp_follow_symlinks=1
139 let g:ctrlp_clear_cache_on_exit=0
Here is my .vimrc, I thought there might be some settings conflicting each other
hi Comment ctermfg=6
"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."
au BufWinLeave *.* mkview
au BufWinEnter *.* silent loadview
"function SetCafeOptions()
"CoffeeCompile
":set nonu
":res -24
":res +24
"endfunction
set encoding=utf-8
set fileencoding=utf-8
colorscheme elflord
set smartindent
set tabstop=4
set expandtab
set shiftwidth=4
"make it autoreload
set autoread
"auto move it last time the position you viewed
"make vim save and load the folding of the document each time it loads"
""also places the cursor in the last place that it was left."
"try to set show ansi color
if &term=="ansi"
set t_Co=0
endif
"set expandtab
filetype on
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
set cscopetag
set cscopequickfix=s-,g-,c-,d-,t-,e-,f-,i-
endif
"let Tlist can close windows at one time
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
" Key map
" Presee F4 and you can open the NERDTree
nnoremap <silent> <F4> :NERDTree<CR>
"nnoremap <silent> <F3> :!/usr/bin/env python %<CR>
" Show function List with Tlist
nnoremap <F12> :TlistToggle<CR>
" Map ctrl+q to ctrlw+ctrlw
"
"nnoremap <silent> <C-q> :<C-w><C-w>
"switch in splitted window
map <c-d> <c-w>l
map <c-a> <c-w>h
"set highlight
set hlsearch
"set autocomplet
"autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby
autocmd BufNewFile,BufRead *.html.erb set filetype=erb.html.eruby
filetype plugin indent on
"auto import python template
autocmd bufnewfile *.py 0r ~/common_lib/python_lib/tmpl.py
map ff :CtrlP<.><cr>
"set NerdTreeSize
let g:NERDTreeWinSize=12
let g:NERDTreeIgnore=['\.vim$', '\~$', '\vendor$']
"auto close the nerdtress window whe you open new file
"let g:ctrlp_dont_split = 'nerdtree'
set nocompatible " explictly get out of vi-compatible mode
set background=dark " we plan to use a dark background
syntax on " syntax highlighting on
set number " turn on line numbers
set ruler "always show current position along the bottom
set incsearch " do highlight as you type you search phrase
set ignorecase " case insensitive by default
set smartcase " if there are caps, go case-sensitive
"Rope vim
"let $PYTHONPATH .= ":~/install/ropehg/rope:~/install/ropehg/ropemode:~/install/ropehg/ropevim"
"source ~/install/ropehg/ropevim/ropevim.vim
"let g:pymode_rope_goto_def_newwin = "new"
"let ropevim_vim_completion=1
"Use Ctrl + ] . to autocomple
inoremap <C-]> <C-R>=RopeCodeAssistInsertMode()<CR>
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>
" Load the whole plugin
let g:pymode = 1
" Load run code plugin
let g:pymode_run = 1
"add ctrlp.vim setting
""
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
let g:ctrlp_custom_ignore = 'tmp$\|\.git$\|\.hg$\|\.svn$\|.rvm$|.bundle$\|vendor'
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=25
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
let g:ctrlp_clear_cache_on_exit=0
"Vundle
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-surround'
Bundle 'Raimondi/delimitMate'
"coffee script"
Bundle 'kchmck/vim-coffee-script'
Bundle 'ack.vim'
Bundle 'matchit.zip'
Bundle 'kien/ctrlp.vim'
"Markdown"
"Bundle 'plasticboy/vim-markdown'
""Vim-scripts repo
"Bundle 'The-NERD-Commenter'
Bundle 'pep8'
""Bundle 'AutoClose'
Bundle 'desert-warm-256'
Bundle 'https://github.com/altercation/vim-colors-solarized.git'
filetype plugin indent on
nmap <leader>a <Esc>:Ack ""
"folding code
nnoremap <space> za
vnoremap <space> zf
" pep8
let g:pep8_map='<leader>8'
"coffee script"
call pathogen#infect()
let Tlist_Use_Right_Window = 1
"autocmd BufEnter * if &filetype == "" | setlocal ft=python | endif
"markdown https://github.com/plasticboy/vim-markdown/wiki"
"let g:vim_markdown_folding_disabled=1
"auto exec ruby and coffee script with F5 , remeber to save file before launching
autocmd FileType python map <leader>p :!python %<cr>
autocmd FileType ruby,rb map <leader>5 :w!<cr>:!ruby %<cr>
autocmd FileType * map <leader>e :qa!<cr>
"set extension .god as a Ruby file"
"au BufNewFile,BufRead *.god set filetype=ruby
"autocmd FileType coffee nmap <F5> :CoffeeCompile<cr>
"autocmd FileType coffee map <F5> :call SetCafeOptions()<cr>
"so ~/.vim/snippets/support_functions.vim
set re=1
autocmd Filetype gitcommit setlocal spell textwidth=72
" enable per-project .vimrc files
set exrc
" " Only execute safe per-project vimrc commands
set secure"
Here are a few tips that should definitely speed up ctrlp :
let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp'
if executable('ag')
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
In the above example, the first option tells ctrlp to persist the cache in the configured location, so when you launch vim again, it will read from there and load the cache (much faster).
The second option configures ctrlp to use ag (the_silver_searcher) instead of vim's native globpath() apis to search for files, this will drastically improve it's scanning speed, if you don't want to use ag, you can even use plain old grep and it still should be significantly faster. Check :h 'g:ctrlp_user_command' for more details.
As I explained here, if you type :help ctrlp-options and read a bit, you will find:
Note #1: by default, wildignore and g:ctrlp_custom_ignore only
apply when globpath() is used to scan for files, thus these options
do not apply when a command defined with g:ctrlp_user_command is
being used.
Thus, you may need to unlet g:ctrlp_user_command (possibly set to a default command) to actually use wildignore. For instance, in your ~/.vimrc, add:
if exists("g:ctrl_user_command")
unlet g:ctrlp_user_command
endif
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*/vendor/*,*/\.git/*
...
After that, you need to refresh your ctrlp cache: in Vim, press F5 in ctrlp mode, or run :CtrlPClearAllCaches, or remove the cache directory directly in your shell:
rm -r ~/.cache/ctrlp/ # On Linux
As for the indexing part (which seems to be your problem), it should follow your ignore rules. You can check the indexed files in ~/.cache/ctrlp/%path%to%your%project%folder.txt.
Last resort for a quick startup
I tried everything I found in different places to improve the indexing speed of my ctrlp, but nothing helped.
At the end, I settled with this:
let g:ctrlp_clear_cache_on_exit = 0
It keeps the ctrlp cache after you close VIM, so the next start up will be fast. And you can update the cache manually by pressing F5 anytime you need.
Found this bit while looking around the interwebs, and it has made indexing and searching for files instant.
let g:ctrlp_user_command = ['.git/', 'git ls-files --cached --others --exclude-standard %s']
I'm not fully grasping what is happening here, so if anyone has a bit more knowledge to dissect this, I'd love to know what's happening behind the scenes.
If you have ripgrep (rg) installed you can use it with CtrlP. It is much faster than the default file search. This is the incantation you need to make it work:
if executable('rg')
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
h/t Elliot Jackson

Vim slow over UNC paths

I am experiencing some very painful lag when accessing directories/files over UNC paths using gVim 7.3 on Windows Vista.
It is slow reading/writing files, as well as tab completiong of directory/file names when opening new buffers. I don't notice this lag when using WordPad though.
Things I've tried:
Cream (apparently they had a fix for directory naming schemes)
Mapping the network drive to z: or something else
Various settings
set ffs=dos
set complete=.,w,b,u,t
set noshellslash
I've tried cygwin, but the same noticeable lag appears there as well. I already have all swap/backup files turned off. Any help greatly appreciated... I've dumped my vimrc for reference
if v:progname =~? "evim"
finish
endif
set nocompatible
:runtime! ftplugin/man.vim
set backspace=indent,eol,start
colorscheme torte " murphy
syn on
set ffs=unix,dos
" portable friendly
set nobackup
set nowritebackup
set noswapfile
set viminfo=
" gui options (http://steveno.wordpress.com/2007/10/08/vim-for-windows/)
set guioptions-=T " No toolbar
set gfn=Consolas:h9:cANSI
set history=50
set ruler
set showcmd
set incsearch
set number
set tabstop=4
set softtabstop=4
set shiftwidth=4
set wrap
set wildmode=longest,list,full " Complete longest string, list alternatives
" then completed next full match, cycling back
function! ToggleHLSearch()
if &hls
set nohls
else
set hls
endif
endfunction
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<CR>
nmap <silent> <C-n> <Esc>:call ToggleHLSearch()<CR>
nmap ,s :source ~/.vimrc<Return>
" change current directory to that of open buffer
nmap ,c :cd %:p:h<Return>
nmap <c-h> <c-w>h<c-w><bar>
nmap <c-l> <c-w>l<c-w><bar>
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map Q gq
" Commenting blocks of text
" ,< <!-- --> html style comments
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR><Esc>:nohlsearch<CR>
" ,/ // comments
map ,/ :s/^/\/\//<CR>
" ,# # comments
map ,# :s/^/#/<CR>
" uncommenting all of the above
"map ,- :s/^\(\/\/|<!-- |#\)\(.*\)\(-->\)*/\1/<CR>
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if has("autocmd")
"&& !exists("autocommands_loaded")
let autocommands_loaded = 1
filetype plugin indent on
augroup vimrcEx
au!
" Remove ALL autocommands for the current group.
autocmd!
autocmd FileType text setlocal textwidth=78
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
au BufRead *.html set filetype=html4
augroup END
" allow editing Word Docs sanely
autocmd BufReadPre *.doc set ro
autocmd BufReadPre *.doc set hlsearch!
autocmd BufReadPost *.doc %!antiword "%"
" uncomment the following to remember the view of the file edited between
" sessions
" au BufWinLeave * mkview
" au BufWinEnter * silent loadview
" run file with PHP CLI (CTRL-M)
autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>
" parser check (CTRL-L)
autocmd FileType php noremap <C-L> :!/usr/bin/php -l %<CR>
" highlight current line only for current buffer
"autocmd BufLeave * setlocal nocursorline
"autocmd BufEnter * setlocal cursorline
au BufRead,BufNewFile *.tea set filetype=tea
"au! Syntax newlang source $VIM/newlanguage.vim
else
set autoindent
endif
the same thing was driving me insane, but there is a fix I just found.
I really do not know why yet, but the problem goes away when you disable plugin/matchparen.vim plugin (changing vim extension would do the trick).
I will definitely look into it as I use parentheses matching a lot.
See
:he swap-file
You can disable swapfiles with :se noswapfile (caution!) or use the `directory` setting to keep the swapfile on a local disk.
Starting vim with the -n option also disables swapfiles; you might want to combine that with -R for readonly mode
Another solution I found is that mounting a UNC path as a local drive letter and let Vim use the drive-letter based paths only.
e.g., \\some-server\path\to\workdir => Z:\path\to\workdir
This eliminates the lag completely unless you have connection problems.

Vim Question: Sparkup doesn't work for files opened from a running Vim session

If I were to open a file with Vim from the command prompt (eg: vim ~/.vimrc), the Sparkup text generation seems to work perfectly fine. For example if I insert:
html:xs
and then push control + e, sparkup generates a nice HTML strict boilerplate. However if I then split to another file from the running Vim session, Sparkup stops working in the newly opened file. It's totally possible that other plugins lose their functionality as well. Here is my .vimrc file:
set nocompatible " use vim defaults
set number " show line numbers
set tags=tags;$HOME/.vim/tags/ "recursively searches directory for 'tags' file
set expandtab " tabs are converted to spac
set tabstop=4 " numbers of spaces of tab character
set shiftwidth=4 " numbers of spaces to (auto)indent
set showcmd " display incomplete commands
set incsearch " do incremental searching
set ruler " show the cursor position all the time
set numberwidth=4 " line numbering takes up 5 spaces
set ignorecase " ignore case when searching
set nowrap " stop lines from wrapping
set incsearch " show search matches as you type
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plugins
filetype plugin indent on " Loads pyflake-vim's ftplugin files automatically when a Python buffer is opened
syntax on " syntax highlighing
colorscheme default
nmap <silent> <c-y> :NERDTreeToggle<CR>
nmap <silent> <c-o> :OpenBookmark
" TagList Plugin Configuration
let Tlist_Ctags_Cmd='/usr/bin/ctags' " point taglist to ctags
let Tlist_GainFocus_On_ToggleOpen = 1 " Focus on the taglist when its toggled
let Tlist_Close_On_Select = 1 " Close when something's selected
let Tlist_Use_Right_Window = 1 " Project uses the left window
let Tlist_File_Fold_Auto_Close = 1 " Close folds for inactive files
" Omnicompletion functions
set ofu=syntaxcomplete#complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
au FileType py set expandtab
map <F2> :previous<CR> " map F2 to open previous buffer
map <F3> :next<CR> " map F3 to open next buffer
map <F5> :TlistToggle<CR> " map F5 to toggle the Tag Listing
map <silent><C-Left> <C-T> " taglist - map Ctrl-LeftArrow to jump to the method/property under your cursor
map <silent><C-Right> <C-]> " taglist - map Ctrl-RhitArrow to jump back to your source code
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc
highlight SpellBad term=reverse ctermbg=Gray ctermfg=Red
And here are some other plugins I have inside ~/.vim/bundles:
IndexedSearch nerdtree snipmate.vim vim-css-color vim-git vim-rails vim-ruby-debugger vim-supertab vim-tcomment
gist pyflakes-vim textile.vim vim-cucumber vim-haml vim-repeat vim-shoulda vim-surround vim-vividchalk
jquery pysmell vim-align vim-fugitive vim-markdown vim-ruby vim-sparkup vim-taglist
Can it be that this plugin is bound to a given FileType and that when you change window the FileType is not the same?
If it doesn't work, try adding your plugin to ftplugins.

Syntax highlighting in terminal vim but not gVIM

I am currently using VIM in the terminal and have perfect syntax highlighting happening. But then when I try to use gvim no matter what type of file or how many times I type: ":syntax on" I don't get any syntax highlighting. Any ideas anyone?
Thank you.
Here is my .vimrc for those who are interested:
" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
" My color theme for vim
colors sorcerer
" Disable line wrapping for now
set nowrap
" Enable the mouse even when vi is used in the terminal
set mouse=a
" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'
" This shows what you are typing as a command. I love this!
set showcmd
" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v
" Gimme some breathing room at the bottom please...
set scrolloff=5
" makes vim usable with screen
set restorescreen
" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
"Kill error bells
set noerrorbells
set visualbell
set t_vb=
" Turn on spell check
" set spell
" Thesaurus!!
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt
" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1
" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden
" Turn on incremental search
set incsearch
set smartcase
" Long history is long
set history=1000
set undolevels=1000
" No need for a vi backup file
set nobackup
" Colors!!
set t_Co=256
" Compatibility
set nocompatible
set formatprg=par
" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0
" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…
" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround
" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
set showmode "show current mode down the bottom
"Setting the status line...
set statusline=%f "tail of the filename
"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" Auto completion options
set wildmode=list:longest "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete
"display tabs and trailing spaces
set list
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•
let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i
command W w !sudo tee % > /dev/null
" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.
" VIM 7.3 features here...
if v:version >= 703
set relativenumber
set undofile
endif
Use :let g:colors_name to see the name of the colourscheme that has been loaded, the value should be 'sorcerer', if it's not then something has gone seriously wrong
Type :hi Operator, you 'xxx' part should be coloured and you should see guifg=<color> in the output.
Put a new line at the top of your .vimrc containing just the word "finish", this will stop vim processing your .vimrc. Using :colors default and :syntax on should be enough to get syntax highlighting turned on. If this works then just move the finish line down through your .vimrc until you find the section that is breaking syntax highlighting.
On windows, gVim uses a file called _vimrc, so check for that as well.
When you type :version in gvim do you see +syntax listed in your features list?
Try comparing that to your regular Vim version. Maybe your gvim build didn't include the syntax highlighting feature.
The issue was fixed once I finally figured out how to get gvim 7.3. Then the syntax highlighting magically came.
Building on Thien's response, I also had the same experience (set syntax=on fails, the menu options succeed but only until Vim is restarted).
The menu option apparently triggers :syn=on, and adding that to _vimrc does enable syntax highlighting persistently where set syntax=on did not. I'll leave it to someone with more experience to explain the difference between those two.
set syntax=xxx was not working for me in gvim 7.3 on Windows XP although it did for vim in cygwin. To get syntax highlighting I had to go to Menu > Syntax > Show filetypes in menu > select syntax. I guess the menu command and the vim commands don't do the same thing with gvim on Windows.

Resources