Created
January 21, 2012 04:03
-
-
Save sirlancelot/1651208 to your computer and use it in GitHub Desktop.
A Vim function to set an option only if it is currently at its default value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " =============================================== | |
| " _ __(_)__ _ ________ | |
| " _| |/ / // ' \/ __/ __/ | |
| " (_)___/_//_/_/_/_/ \__/ | |
| " | |
| " Maintainer: Matthew Pietz | |
| " | |
| " =============================================== | |
| " Put your overrides in here | |
| runtime! vimrc.local.vim | |
| " The goods | |
| fun! SetIfDefault(Option, New) | |
| let l:Stored = eval('&'.a:Option) | |
| exe 'set '.a:Option.'&' | " reset the option back to its default | |
| " Set the New option if the stored one matches the current setting | |
| exe 'set '.a:Option.'='.(l:Stored == eval('&'.a:Option) ? a:New : l:Stored) | |
| endfun " ;( | |
| " Use it like this... | |
| call SetIfDefault('backupdir', '$HOME/.vimbackup') | |
| call SetIfDefault('directory', '$HOME/.vimswap') | |
| call SetIfDefault('undodir', '$HOME/.vim/undo') | |
| " Or even better... | |
| call SetIfDefault('undodir', '$HOME/Dropbox/vim/undo') | |
| call SetIfDefault('backupdir', '$HOME/Dropbox/vim/backup') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can also discuss this on Reddit.