" EDITOR SETTINGS
" Save 'runtimepath' in case it was changed by the system's configuration
-" files.
+" files. Also save 'diff' as set all& resets it; but somehow later (after
+" sourcing the vimrc - for example in a VimEnter autocmd) it gets
+" automagically restored to the correct value.
if has('eval')
let s:save_runtimepath = &runtimepath
+ let s:save_diff = &diff
endif
" Reset all options (except 'term', 'lines' and 'columns'). This makes sure a
" system wide configuration file doesn't change default values.
" And restore it after all other options were reset.
if has('eval')
let &runtimepath = s:save_runtimepath
+ let &diff = s:save_diff
unlet s:save_runtimepath
+ unlet s:save_diff
endif
" Make sure Vim (and not Vi) settings are used.
set ignorecase
set smartcase
-" Activate spell checking, use English as default. Don't use spell checking
-" when diffing.
-if exists('+spell') && has('syntax') && !&diff
- set spell
+" Activate spell checking, use English as default.
+if exists('+spell') && has('syntax')
+ " But not when diffing as spell checking is distracting in this case.
+ if !&diff
+ set spell
+ endif
set spelllang=en_us
endif
endif
-" CUSTOM FUNCTIONS
+" CUSTOM FUNCTIONS AND COMMANDS
if has('eval')
- " New text-objects ii and ai to work on text with the same indentation.
- " Thanks to
- " http://vim.wikia.com/index.php?title=Indent_text_object&oldid=27126
- " (visited on 2011-11-19).
+" New text-objects ii and ai to work on text with the same indentation. Thanks
+" to http://vim.wikia.com/index.php?title=Indent_text_object&oldid=27126
+" (visited on 2011-11-19).
onoremap <silent> ai :<C-U>call <SID>IndTxtObj(0)<CR>
onoremap <silent> ii :<C-U>call <SID>IndTxtObj(1)<CR>
vnoremap <silent> ai :<C-U>call <SID>IndTxtObj(0)<CR><Esc>gv
endif
endfunction
+" 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 than 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