+ " 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