+" Highlight lines longer than 78 characters. Thanks to Tony Mechelynck
+" <antoine.mechelynck@gmail.com> from the Vim mailing list. It can easily be
+" disabled when necessary with :2match (in Vim >= 700).
+ if !&diff && exists(':2match')
+ " Use ColorColumn for overlong lines if available and my color
+ " scheme is used.
+ if &t_Co == 256 && s:HasSyntaxGroup('ColorColumn')
+ 2match ColorColumn /\%>78v./
+ else
+ 2match Todo /\%>78v./
+ endif
+ elseif !&diff
+ match Todo /\%>78v./
+ endif
+
+ if exists('*matchadd')
+" Highlight some important keywords in all documents.
+ let l:todos = ['TODO', 'XXX', 'FIXME',
+ \ 'CHANGED', 'REMOVED', 'DELETED']
+ " Compatibility fix for Vim 6.4 which can't handle for in function
+ " (without function it's ignored).
+ execute ' for l:x in l:todos'
+ \ '| call matchadd("Todo", l:x)'
+ \ '| endfor'
+
+" Highlight Unicode whitespace which is no normal whitespace (0x20).
+ let l:spaces = ['00a0', '1680', '180e', '2000', '2001', '2002',
+ \ '2003', '2004', '2005', '2006', '2007', '2008',
+ \ '2009', '200a', '200b', '200c', '200d', '202f',
+ \ '205f', '2060', '3000', 'feff']
+ " Compatibility fix for Vim 6.4. Escape \ inside the " string or
+ " it won't work!
+ execute ' for l:x in l:spaces'
+ \ '| call matchadd("Error", "\\%u" . l:x)'
+ \ '| endfor'
+
+" Special highlight for tabs to reduce their visibility in contrast to other
+" SpecialKey characters (e.g. ^L).
+ if &t_Co == 256 && s:HasSyntaxGroup('specialKeyTab')
+ call matchadd('specialKeyTab', '\t')
+ endif
+ endif
+ endfunction
+" Enable highlights for the current and all new windows. Thanks to bairui in
+" #vim on Freenode (2012-04-01 00:22 CEST) for the WinEnter suggestion.
+ call s:CustomSyntaxHighlights()
+ if has('autocmd')
+ augroup vimrc
+ autocmd WinEnter * call s:CustomSyntaxHighlights()
+ augroup END
+ endif
+
+" Settings for specific filetypes.
+
+ " C
+ let g:c_no_if0_fold = 1 " fix weird double fold in #if0 in recent versions
+ " Haskell.
+ let g:hs_highlight_delimiters = 1
+ let g:hs_highlight_boolean = 1
+ let g:hs_highlight_types = 1
+ let g:hs_highlight_more_types = 1
+ " Java.
+ let g:java_highlight_java_lang_ids = 1 " color java.lang.* identifiers
+ " Perl.
+ let g:perl_fold = 1
+ let g:perl_fold_blocks = 1
+ let g:perl_nofold_packages = 1
+ let g:perl_include_pod = 1 " syntax coloring for PODs
+ " PHP.
+ let g:php_folding = 3 " fold functions
+ let g:php_short_tags = 0 " no short tags (<? .. ?>), not always usable
+ let g:php_sql_query = 1 " highlight SQL queries in strings
+ " Python.
+ let g:python_highlight_all = 1
+ " Shell.
+ let g:sh_noisk = 1 " don't add . to 'iskeyword'
+ let g:sh_is_posix = 1 " POSIX shell (e.g. dash) is compatible enough
+ let g:sh_fold_enabled = 7 " functions (1), heredoc (2) and if/do/for (4)
+ " Vim.
+ let g:vimsyn_embed = 0 " don't highlight embedded languages
+ let g:vimsyn_folding = 'af' " folding for autogroups (a) and functions (f)
+ " XML.
+ let g:xml_syntax_folding = 1
+endif
+
+
+" PLUGIN SETTINGS
+
+if has('eval')
+" Use pathogen which allows one 'runtimepath' entry per plugin. This makes
+" installing/removing/updating plugins simple. (Used for plugins with more
+" than one file.) Ignore errors in case pathogen is not installed.
+ if v:version >= 700
+ silent! execute 'call pathogen#infect()'
+ endif
+
+" Settings for securemodelines.
+ " Only allow items I need (also includes spl which is not enabled by
+ " default).
+ if v:version >= 700 " need lists
+ let g:secure_modelines_allowed_items = ['ft', 'spl', 'fdm',
+ \ 'sw', 'sts', 'noet']
+ endif
+
+" Settings for the NERD commenter.
+ " Don't create any mappings I don't want to use.
+ let g:NERDCreateDefaultMappings = 0
+ " Map toggle comment.
+ nmap <Leader><Leader> <Plug>NERDCommenterToggle
+
+" XPTemplate settings.
+ " Try to maintain snippet rendering even after editing outside of a
+ " snippet.
+ let g:xptemplate_strict = 0
+ " Don't complete any braces automatically.
+ let g:xptemplate_brace_complete = 0
+ " Only highlight the current placeholder.
+ let g:xptemplate_highlight = 'current'
+
+" CtrlP settings.
+ " Don't manage the working directory (the default setting is too slow for
+ " me).
+ let g:ctrlp_working_path_mode = 0
+
+ " Path to cache directory. I prefer to keep generated files as local as
+ " possible.
+ let g:ctrlp_cache_dir = $HOME . '/.vim/cache/ctrlp'
+ " Permanent cache, cleared by a crontab entry. Use <F5> to update the
+ " cache manually.
+ let g:ctrlp_clear_cache_on_exit = 0
+
+ " Don't switch the window if the selected buffer is already open. I want
+ " to open another view on this buffer in most cases.
+ let g:ctrlp_switch_buffer = 0
+
+" FSWitch settings.
+ " Defaults don't work well for my projects.
+ augroup vimrc
+ autocmd BufEnter *.cc let b:fswitchdst = 'h'
+ \ | let b:fswitchlocs = './'
+ autocmd BufEnter *.h let b:fswitchdst = 'cc,c'
+ \ | let b:fswitchlocs = './'
+ augroup END
+
+ " Switch to corresponding header/source file.
+ nnoremap <silent> <Leader>h :FSHere<CR>
+
+" netrw settings.
+ " Don't create ~/.vim/.netrwhist history file.
+ let g:netrw_dirhistmax = 0
+endif
+
+
+" AUTO COMMANDS
+
+" Use a custom auto group to prevent problems when the vimrc files is sourced
+" twice.
+if has('autocmd')
+ augroup vimrc
+
+" Go to last position of opened files. Taken from :help last-position-jump.
+ autocmd BufReadPost *
+ \ if line("'\"") > 1 && line("'\"") <= line('$') |
+ \ execute "normal! g'\"" |
+ \ endif
+" But not for Git commits, go to beginning of the file.
+ autocmd BufReadPost COMMIT_EDITMSG normal! gg
+
+" Make sure 'list' and 'number' is disabled in help files. This is necessary
+" when switching to a help buffer which is in the background with :buffer as
+" these options are local to windows (and not only to buffers). This happens
+" because I often want to use only one window and thus the help buffer is in
+" the background.
+ autocmd BufWinEnter *.txt
+ \ if &filetype == 'help' |
+ \ setlocal nolist |
+ \ setlocal nonumber |
+ \ endif
+
+" Automatically disable 'paste' mode when leaving insert mode. Thanks to
+" Raimondi in #vim on Freenode (2010-08-14 23:01 CEST). Very useful as I only
+" want to paste once and then 'paste' gets automatically unset. InsertLeave
+" doesn't exist in older Vims. Use "*p to paste X11's selection, no need for
+" 'paste' in this case.
+ if exists('##InsertLeave')
+ autocmd InsertLeave * set nopaste
+ endif
+
+" Write all files when running :mak[e] before 'makeprg' is called.
+" QuickFixCmdPre doesn't exist in older Vims.
+ if exists('##QuickFixCmdPre')
+ autocmd QuickFixCmdPre * wall
+ endif
+
+" Don't ignore case while in insert mode, but ignore case in all other modes.
+" This causes <C-N>/<C-P> to honor the case and thus only complete matching
+" capitalization. But while searching (/) 'ignorecase' is used.
+" InsertEnter/InsertLeave doesn't exist in older Vims.
+ if exists('##InsertEnter') && exists('##InsertLeave')
+ autocmd InsertEnter * set noignorecase
+ autocmd InsertLeave * set ignorecase
+ endif
+
+" Display a warning when editing a file which contains "do not edit" (ignoring
+" the case) and similar messages in the first lines of the file, for example
+" template files which were preprocessed or auto-generated files. Especially
+" useful when the header is not displayed on the first screen, e.g. when the
+" old position is restored.
+ function! s:SearchForDoNotEditHeader()
+ " Only search the first 20 lines to prevent false positives, e.g.
+ " in scripts which write files containing this warning and ignore
+ " the case (\c). (Can't use search()'s {stopline} as we might not
+ " start searching from the top.)
+ let l:search = '\c\(do not \(edit\|modify\)\|autogenerated by\)'
+ let l:match = search(l:search, 'n')
+ if l:match == 0 || l:match > 20
+ return
+ endif
+
+ echoerr 'Do not edit this file! (Maybe a template file.)'
+ endfunction
+ autocmd BufRead * call s:SearchForDoNotEditHeader()
+
+" AFTER/FTPLUGIN AUTO COMMANDS
+
+" Disable spell checking for files which don't need it.
+ autocmd FileType deb setlocal nospell
+ autocmd FileType diff setlocal nospell
+ autocmd FileType tar setlocal nospell
+" Fix to allow Vim edit crontab files as crontab doesn't work with
+" backupcopy=auto.
+ autocmd FileType crontab setlocal backupcopy=yes
+" Don't use the modeline in git commits as the diff created by `git commit -v`
+" may contain one which could change the filetype or other settings of the
+" commit buffer. Also make sure we use only 72 characters per line which is
+" the recommendation for git commit messages (http://tpope.net/node/106).
+ autocmd FileType gitcommit let g:secure_modelines_allowed_items = [] |
+ \ setlocal textwidth=72
+" Fix 'include' setting for shell files to recognize '.' and 'source'
+" commands. Use &l:include instead of setlocal which requires excessive
+" escaping of \.
+ autocmd FileType sh let &l:include = '^\s*\(\.\|source\)\s\+'
+" Use the same comment string as for Vim files in Vimperator files.
+ autocmd FileType vimperator setlocal commentstring=\"%s
+" Use TeX compiler for (La)TeX files.
+ autocmd FileType tex compiler tex
+
+" FTDETECT AUTO COMMANDS
+
+" Recognize .md as markdown files (Vim default is .mkd).
+ autocmd BufRead,BufNewFile *.md set filetype=mkd
+" Recognize .test as Tcl files.
+ autocmd BufRead,BufNewFile *.test set filetype=tcl
+
+" OTHER AUTO COMMANDS
+
+" Disable spell checking, displaying of list characters and long lines when
+" viewing documentation.
+ autocmd BufReadPost /usr/share/doc/* setlocal nospell nolist | 2match
+
+" Use diff filetype for mercurial patches in patch queue.
+ autocmd BufReadPost */.hg/patches/* set filetype=diff
+
+ augroup END
+endif
+
+
+" CUSTOM FUNCTIONS AND COMMANDS
+
+if has('eval')
+" Convenient command to see the difference between the current buffer and the
+" file it was loaded from, thus the changes you made. Thanks to the
+" vimrc_example.vim file in Vim's source. Modified to use the same filetype
+" for the diffed file as the filetype for the original file.
+ if !exists(':DiffOrig')
+ command DiffOrig
+ \ let s:diff_orig_filetype = &filetype
+ \ | vertical new
+ \ | let &filetype = s:diff_orig_filetype
+ \ | unlet s:diff_orig_filetype
+ \ | set buftype=nofile
+ \ | read ++edit #
+ \ | 0d_
+ \ | diffthis
+ \ | wincmd p
+ \ | diffthis
+ endif
+endif