diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index b8ffa6569db959..a7a2381228cf89 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -1063,23 +1063,28 @@ giving the mapping. Defaults without a .vimrc file ~ *defaults.vim* *E1187* -If Vim is started normally and no user vimrc file is found, the -$VIMRUNTIME/defaults.vim script is loaded. This will set 'compatible' off, -switch on syntax highlighting and a few more things. See the script for -details. NOTE: this is done since Vim 8.0, not in Vim 7.4. (it was added in -patch 7.4.2111 to be exact). - -This should work well for new Vim users. If you create your own .vimrc, it is -recommended to add these lines somewhere near the top: > +If Vim is started normally, the $VIMRUNTIME/defaults.vim script is loaded. +This will set 'compatible' off, switch on syntax highlighting and a few more +things. See the script for details. NOTE: this is done since Vim 8.0, not in +Vim 7.4. (it was added in patch 7.4.2111 to be exact). + +This should work well for new Vim users. If you create your own .vimrc, +defaults.vim will always be loaded before your own .vimrc, so that you +can revert settings that have been set. If you don't like some of the +defaults, you can still source defaults.vim and revert individual settings. +See the defaults.vim file for hints on how to revert each item. + +Note: since patch 9.1.XXXX Vim will always load the defaults.vim file even +when a user vimrc file has been found. If you do not want this behaviour, you +can opt-out of sourcing defaults.vim by setting the environment variable +`$VIM_NO_SOURCE_DEFAULTS`. + +Previously you had to explicitly source defaults.vim by adding those lines at +the top: > + unlet! skip_defaults_vim source $VIMRUNTIME/defaults.vim -Then Vim works like before you had a .vimrc. Copying $VIMRUNTIME/vimrc_example -is way to do this. Alternatively, you can copy defaults.vim to your .vimrc -and modify it (but then you won't get updates when it changes). - -If you don't like some of the defaults, you can still source defaults.vim and -revert individual settings. See the defaults.vim file for hints on how to -revert each item. +< *skip_defaults_vim* If you use a system-wide vimrc and don't want defaults.vim to change settings, set the "skip_defaults_vim" variable. If this was set and you want to load diff --git a/src/main.c b/src/main.c index e5faaa720190c2..f7b95d50e2badf 100644 --- a/src/main.c +++ b/src/main.c @@ -3261,6 +3261,7 @@ source_startup_scripts(mparm_T *parmp) /* * Try to read initialization commands from the following places: * - environment variable VIMINIT + * - defaults.vim unless $VIM_NO_SOURCE_DEFAULTS is set * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise) * - second user vimrc file ($VIM/.vimrc for Dos) * - environment variable EXINIT @@ -3270,6 +3271,10 @@ source_startup_scripts(mparm_T *parmp) */ if (process_env((char_u *)"VIMINIT", TRUE) != OK) { + int loaded_vimrc = NOTDONE; + if (mch_getenv("VIM_NO_SOURCE_DEFAULTS") == NULL) + loaded_vimrc = do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, + DOSO_NONE, NULL); if (do_source((char_u *)USR_VIMRC_FILE, TRUE, DOSO_VIMRC, NULL) == FAIL #ifdef USR_VIMRC_FILE2 @@ -3295,7 +3300,7 @@ source_startup_scripts(mparm_T *parmp) && do_source((char_u *)USR_EXRC_FILE2, FALSE, DOSO_NONE, NULL) == FAIL #endif - && !has_dash_c_arg) + && !has_dash_c_arg && loaded_vimrc != OK) { // When no .vimrc file was found: source defaults.vim. if (do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE,