Skip to content

Commit 8c08b5b

Browse files
committed
patch 7.4.2111
Problem: Defaults are very conservative. Solution: Move settings from vimrc_example.vim to defaults.vim. Load defaults.vim if no .vimrc was found.
1 parent eac784e commit 8c08b5b

14 files changed

Lines changed: 243 additions & 122 deletions

File tree

Filelist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,9 @@ RT_ALL = \
526526
runtime/macros/urm/examples \
527527
runtime/macros/urm/urm \
528528
runtime/macros/urm/urm.vim \
529-
runtime/mswin.vim \
529+
runtime/defaults.vim \
530530
runtime/evim.vim \
531+
runtime/mswin.vim \
531532
runtime/optwin.vim \
532533
runtime/ftplugin.vim \
533534
runtime/ftplugof.vim \

runtime/defaults.vim

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
" The default vimrc file.
2+
"
3+
" Maintainer: Bram Moolenaar <[email protected]>
4+
" Last change: 2016 Jul 28
5+
"
6+
" This is loaded if no vimrc file was found.
7+
" Except when Vim is run with "-u NONE" or "-C".
8+
" Individual settings can be reverted with ":set option&".
9+
" Other commands can be reverted as mentioned below.
10+
11+
" When started as "evim", evim.vim will already have done these settings.
12+
if v:progname =~? "evim"
13+
finish
14+
endif
15+
16+
" Use Vim settings, rather than Vi settings (much better!).
17+
" This must be first, because it changes other options as a side effect.
18+
set nocompatible
19+
20+
" Allow backspacing over everything in insert mode.
21+
set backspace=indent,eol,start
22+
23+
set history=200 " keep 200 lines of command line history
24+
set ruler " show the cursor position all the time
25+
set showcmd " display incomplete commands
26+
set wildmenu " display completion matches in a status line
27+
28+
" Do incremental searching when it's possible to timeout.
29+
if has('reltime')
30+
set incsearch
31+
endif
32+
33+
" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
34+
" confusing.
35+
set nrformats-=octal
36+
37+
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
38+
if has('win32')
39+
set guioptions-=t
40+
endif
41+
42+
" Don't use Ex mode, use Q for formatting.
43+
" Revert with ":unmap Q".
44+
map Q gq
45+
46+
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
47+
" so that you can undo CTRL-U after inserting a line break.
48+
" Revert with ":iunmap <C-U>".
49+
inoremap <C-U> <C-G>u<C-U>
50+
51+
" In many terminal emulators the mouse works just fine. By enabling it you
52+
" can position the cursor, Visually select and scroll with the mouse.
53+
if has('mouse')
54+
set mouse=a
55+
endif
56+
57+
" Switch syntax highlighting on when the terminal has colors or when using the
58+
" GUI (which always has colors).
59+
if &t_Co > 2 || has("gui_running")
60+
" Revert with ":syntax off".
61+
syntax on
62+
63+
" I like highlighting strings inside C comments.
64+
" Revert with ":unlet c_comment_strings".
65+
let c_comment_strings=1
66+
endif
67+
68+
" Only do this part when compiled with support for autocommands.
69+
if has("autocmd")
70+
71+
" Enable file type detection.
72+
" Use the default filetype settings, so that mail gets 'tw' set to 72,
73+
" 'cindent' is on in C files, etc.
74+
" Also load indent files, to automatically do language-dependent indenting.
75+
" Revert with ":filetype off".
76+
filetype plugin indent on
77+
78+
" Put these in an autocmd group, so that you can revert them with:
79+
" ":augroup vimStartup | au! | augroup END"
80+
augroup vimStartup
81+
au!
82+
83+
" When editing a file, always jump to the last known cursor position.
84+
" Don't do it when the position is invalid or when inside an event handler
85+
" (happens when dropping a file on gvim).
86+
autocmd BufReadPost *
87+
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
88+
\ exe "normal! g`\"" |
89+
\ endif
90+
91+
augroup END
92+
93+
endif " has("autocmd")
94+
95+
" Convenient command to see the difference between the current buffer and the
96+
" file it was loaded from, thus the changes you made.
97+
" Only define it when not defined already.
98+
" Revert with: ":delcommand DiffOrig".
99+
if !exists(":DiffOrig")
100+
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
101+
\ | wincmd p | diffthis
102+
endif
103+
104+
if has('langmap') && exists('+langnoremap')
105+
" Prevent that the langmap option applies to characters that result from a
106+
" mapping. If unset (default), this may break plugins (but it's backward
107+
" compatible).
108+
set langnoremap
109+
endif

runtime/doc/options.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 7.4. Last change: 2016 Jul 12
1+
*options.txt* For Vim version 7.4. Last change: 2016 Jul 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -887,7 +887,8 @@ A jump table for the options with a short description can be found at |Q_op|.
887887
done with ":syntax on".
888888

889889
*'backspace'* *'bs'*
890-
'backspace' 'bs' string (default "")
890+
'backspace' 'bs' string (default "", set to "indent,eol,start"
891+
in |defaults.vim|)
891892
global
892893
{not in Vi}
893894
Influences the working of <BS>, <Del>, CTRL-W and CTRL-U in Insert
@@ -1696,7 +1697,7 @@ A jump table for the options with a short description can be found at |Q_op|.
16961697

16971698
*'compatible'* *'cp'* *'nocompatible'* *'nocp'*
16981699
'compatible' 'cp' boolean (default on, off when a |vimrc| or |gvimrc|
1699-
file is found)
1700+
file is found, reset in |defaults.vim|)
17001701
global
17011702
{not in Vi}
17021703
This option has the effect of making Vim either more Vi-compatible, or
@@ -3725,8 +3726,10 @@ A jump table for the options with a short description can be found at |Q_op|.
37253726
screen.
37263727

37273728
*'guioptions'* *'go'*
3728-
'guioptions' 'go' string (default "egmrLtT" (MS-Windows),
3729-
"aegimrLtT" (GTK, Motif and Athena))
3729+
'guioptions' 'go' string (default "egmrLtT" (MS-Windows, "t" is
3730+
removed in |defaults.vim|),
3731+
"aegimrLtT" (GTK, Motif and Athena),
3732+
)
37303733
global
37313734
{not in Vi}
37323735
{only available when compiled with GUI enabled}
@@ -4048,7 +4051,8 @@ A jump table for the options with a short description can be found at |Q_op|.
40484051
NOTE: This option is reset when 'compatible' is set.
40494052

40504053
*'history'* *'hi'*
4051-
'history' 'hi' number (Vim default: 50, Vi default: 0)
4054+
'history' 'hi' number (Vim default: 50, Vi default: 0,
4055+
set to 200 in |defaults.vim|)
40524056
global
40534057
{not in Vi}
40544058
A history of ":" commands, and a history of previous search patterns
@@ -4300,7 +4304,8 @@ A jump table for the options with a short description can be found at |Q_op|.
43004304
evaluating 'includeexpr' |textlock|.
43014305

43024306
*'incsearch'* *'is'* *'noincsearch'* *'nois'*
4303-
'incsearch' 'is' boolean (default off)
4307+
'incsearch' 'is' boolean (default off, set in |defaults.vim| if the
4308+
+reltime feature is supported)
43044309
global
43054310
{not in Vi}
43064311
{not available when compiled without the
@@ -4684,7 +4689,7 @@ A jump table for the options with a short description can be found at |Q_op|.
46844689
< Warning: This deletes all menus that you defined yourself!
46854690

46864691
*'langnoremap'* *'lnr'* *'nolangnoremap'* *'nolnr'*
4687-
'langnoremap' 'lnr' boolean (default off)
4692+
'langnoremap' 'lnr' boolean (default off, set in |defaults.vim|)
46884693
global
46894694
{not in Vi}
46904695
{only available when compiled with the |+langmap|
@@ -5150,7 +5155,8 @@ A jump table for the options with a short description can be found at |Q_op|.
51505155
set and to the Vim default value when 'compatible' is reset.
51515156

51525157
*'mouse'* *E538*
5153-
'mouse' string (default "", "a" for GUI, MS-DOS and Win32)
5158+
'mouse' string (default "", "a" for GUI, MS-DOS and Win32,
5159+
set to "a" in |defaults.vim|)
51545160
global
51555161
{not in Vi}
51565162
Enable the use of the mouse. Only works for certain terminals
@@ -5316,7 +5322,8 @@ A jump table for the options with a short description can be found at |Q_op|.
53165322
Negative or zero value means no thread scheduling.
53175323

53185324
*'nrformats'* *'nf'*
5319-
'nrformats' 'nf' string (default "bin,octal,hex")
5325+
'nrformats' 'nf' string (default "bin,octal,hex",
5326+
set to "bin,hex" in |defaults.vim|)
53205327
local to buffer
53215328
{not in Vi}
53225329
This defines what bases Vim will consider for numbers when using the
@@ -5986,7 +5993,7 @@ A jump table for the options with a short description can be found at |Q_op|.
59865993
security reasons.
59875994

59885995
*'ruler'* *'ru'* *'noruler'* *'noru'*
5989-
'ruler' 'ru' boolean (default off)
5996+
'ruler' 'ru' boolean (default off, set in |defaults.vim|)
59905997
global
59915998
{not in Vi}
59925999
{not available when compiled without the
@@ -6619,8 +6626,8 @@ A jump table for the options with a short description can be found at |Q_op|.
66196626
"n" flag to 'cpoptions'.
66206627

66216628
*'showcmd'* *'sc'* *'noshowcmd'* *'nosc'*
6622-
'showcmd' 'sc' boolean (Vim default: on, off for Unix, Vi default:
6623-
off)
6629+
'showcmd' 'sc' boolean (Vim default: on, off for Unix,
6630+
Vi default: off, set in |defaults.vim|)
66246631
global
66256632
{not in Vi}
66266633
{not available when compiled without the
@@ -8377,7 +8384,7 @@ A jump table for the options with a short description can be found at |Q_op|.
83778384

83788385

83798386
*'wildmenu'* *'wmnu'* *'nowildmenu'* *'nowmnu'*
8380-
'wildmenu' 'wmnu' boolean (default off)
8387+
'wildmenu' 'wmnu' boolean (default off, set in |defaults.vim|)
83818388
global
83828389
{not in Vi}
83838390
{not available if compiled without the |+wildmenu|

runtime/doc/starting.txt

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*starting.txt* For Vim version 7.4. Last change: 2016 Jul 03
1+
*starting.txt* For Vim version 7.4. Last change: 2016 Jul 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -806,13 +806,13 @@ accordingly. Vim proceeds in this order:
806806
For the Macintosh the $VIMRUNTIME/macmap.vim is read.
807807

808808
*VIMINIT* *.vimrc* *_vimrc* *EXINIT* *.exrc* *_exrc* *$MYVIMRC*
809-
c. Four places are searched for initializations. The first that exists
809+
c. Five places are searched for initializations. The first that exists
810810
is used, the others are ignored. The $MYVIMRC environment variable is
811811
set to the file that was first found, unless $MYVIMRC was already set
812812
and when using VIMINIT.
813-
- The environment variable VIMINIT (see also |compatible-default|) (*)
814-
The value of $VIMINIT is used as an Ex command line.
815-
- The user vimrc file(s):
813+
I The environment variable VIMINIT (see also |compatible-default|) (*)
814+
The value of $VIMINIT is used as an Ex command line.
815+
II The user vimrc file(s):
816816
"$HOME/.vimrc" (for Unix and OS/2) (*)
817817
"$HOME/.vim/vimrc" (for Unix and OS/2) (*)
818818
"s:.vimrc" (for Amiga) (*)
@@ -829,13 +829,14 @@ accordingly. Vim proceeds in this order:
829829
Note: For MS-DOS and Win32, "$HOME" is checked first. If no
830830
"_vimrc" or ".vimrc" is found there, "$VIM" is tried.
831831
See |$VIM| for when $VIM is not set.
832-
- The environment variable EXINIT.
833-
The value of $EXINIT is used as an Ex command line.
834-
- The user exrc file(s). Same as for the user vimrc file, but with
835-
"vimrc" replaced by "exrc". But only one of ".exrc" and "_exrc" is
836-
used, depending on the system. And without the (*)!
837-
- You would usually have "syntax on" and/or "filetype on" commands,
838-
which trigger initializing filetype detection, see |syntax-loading|.
832+
III The environment variable EXINIT.
833+
The value of $EXINIT is used as an Ex command line.
834+
IV The user exrc file(s). Same as for the user vimrc file, but with
835+
"vimrc" replaced by "exrc". But only one of ".exrc" and "_exrc" is
836+
used, depending on the system. And without the (*)!
837+
V The default vimrc file, $VIMRUNTIME/defaults.vim. This sets up
838+
options values and has "syntax on" and "filetype on" commands,
839+
which is what most new users will want. See |defaults.vim|.
839840

840841
d. If the 'exrc' option is on (which is not the default), the current
841842
directory is searched for three files. The first that exists is used,
@@ -912,6 +913,9 @@ accordingly. Vim proceeds in this order:
912913
The |v:vim_did_enter| variable is set to 1.
913914
The |VimEnter| autocommands are executed.
914915

916+
The $MYVIMRC or $MYGVIMRC file will be set to the first found vimrc and/or
917+
gvimrc file.
918+
915919
Some hints on using initializations:
916920

917921
Standard setup:
@@ -958,33 +962,54 @@ problems if you have a file with only <NL>s and have a line like
958962

959963
*compatible-default*
960964
When Vim starts, the 'compatible' option is on. This will be used when Vim
961-
starts its initializations. But as soon as a user vimrc file is found, or a
962-
vimrc file in the current directory, or the "VIMINIT" environment variable is
963-
set, it will be set to 'nocompatible'. This has the side effect of setting or
964-
resetting other options (see 'compatible'). But only the options that have
965-
not been set or reset will be changed. This has the same effect like the
966-
value of 'compatible' had this value when starting Vim. Note that this
967-
doesn't happen for the system-wide vimrc file nor when Vim was started with
968-
the |-u| command line argument. It does also happen for gvimrc files. The
969-
$MYVIMRC or $MYGVIMRC file will be set to the first found vimrc and/or gvimrc
970-
file.
965+
starts its initializations. But as soon as:
966+
- a user vimrc file is found, or
967+
- a vimrc file in the current directory, or
968+
- the "VIMINIT" environment variable is set, or
969+
- the "-N" command line argument is given, or
970+
even when no vimrc file exists.
971+
- the |defaults.vim| script is loaded, or
972+
- gvimrc file was found,
973+
then it will be set to 'nocompatible'.
974+
975+
Note that this does NOT happen when a system-wide vimrc file was found.
976+
977+
This has the side effect of setting or resetting other options (see
978+
'compatible'). But only the options that have not been set or reset will be
979+
changed. This has the same effect like the value of 'compatible' had this
980+
value when starting Vim.
981+
982+
'compatible is NOT reset, and |defaults.vim| is not loaded:
983+
- when Vim was started with the |-u| command line argument, especially with
984+
"-u NONE", or
985+
- when started with the |-C| command line argument, or
986+
- when the name of the executable ends in "ex". (This has been done to make
987+
Vim behave like "ex", when it is started as "ex")
971988

972989
But there is a side effect of setting or resetting 'compatible' at the moment
973990
a .vimrc file is found: Mappings are interpreted the moment they are
974991
encountered. This makes a difference when using things like "<CR>". If the
975992
mappings depend on a certain value of 'compatible', set or reset it before
976993
giving the mapping.
977994

978-
The above behavior can be overridden in these ways:
979-
- If the "-N" command line argument is given, 'nocompatible' will be used,
980-
even when no vimrc file exists.
981-
- If the "-C" command line argument is given, 'compatible' will be used, even
982-
when a vimrc file exists.
983-
- If the "-u {vimrc}" argument is used, 'compatible' will be used.
984-
- When the name of the executable ends in "ex", then this works like the "-C"
985-
argument was given: 'compatible' will be used, even when a vimrc file
986-
exists. This has been done to make Vim behave like "ex", when it is started
987-
as "ex".
995+
*defaults.vim*
996+
If Vim is started normally and no user vimrc file is found, the
997+
$VIMRUTIME/defaults.vim script is loaded. This will set 'compatible' off,
998+
switch on syntax highlighting and a few more things. See the script for
999+
details. NOTE: this is done since Vim 8.0, not in Vim 7.4. (it was added in
1000+
patch 7.4.2111 to be exact).
1001+
1002+
This should work well for new Vim users. If you create your own .vimrc, it is
1003+
recommended to add this line somewhere near the top: >
1004+
source $VIMRUNTIME/defaults.vim
1005+
Then Vim works like before you had a .vimrc. Copying $VIMRUNTIME/vimrc_example
1006+
is way to do this. Alternatively, you can copy defaults.vim to your .vimrc
1007+
and modify it.
1008+
1009+
If you don't like some of the defaults, you can still source defaults.vim and
1010+
revert individual settings. See the defaults.vim file for hints on how to
1011+
revert each item.
1012+
9881013

9891014
Avoiding trojan horses: *trojan-horse*
9901015
While reading the "vimrc" or the "exrc" file in the current directory, some

runtime/evim.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim script for Evim key bindings
22
" Maintainer: Bram Moolenaar <[email protected]>
3-
" Last Change: 2006 Mar 29
3+
" Last Change: 2016 Jul 24
44

55
" Don't use Vi-compatible mode.
66
set nocompatible
@@ -63,4 +63,12 @@ if has("autocmd")
6363

6464
endif " has("autocmd")
6565

66+
" Add optional packages.
67+
"
68+
" The matchit plugin makes the % command work better, but it is not backwards
69+
" compatible.
70+
if has('syntax') && has('eval')
71+
packadd matchit
72+
endif
73+
6674
" vim: set sw=2 :

0 commit comments

Comments
 (0)