blob: b848217cd9130aca2852084d9c368c3d8f681505 [file] [log] [blame]
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +02001" The default vimrc file.
2"
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar314dd792019-02-03 15:27:20 +01004" Last change: 2019 Jan 26
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +02005"
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.
12if v:progname =~? "evim"
13 finish
14endif
15
Bram Moolenaarb07a82b2016-09-03 20:08:56 +020016" Bail out if something that ran earlier, e.g. a system wide vimrc, does not
17" want Vim to use these default values.
18if exists('skip_defaults_vim')
19 finish
20endif
21
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020022" Use Vim settings, rather than Vi settings (much better!).
23" This must be first, because it changes other options as a side effect.
Bram Moolenaar0f39a822017-03-16 14:19:36 +010024" Avoid side effects when it was already reset.
25if &compatible
26 set nocompatible
27endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020028
Bram Moolenaar33ccb242017-04-01 16:59:29 +020029" When the +eval feature is missing, the set command above will be skipped.
30" Use a trick to reset compatible only when the +eval feature is missing.
Bram Moolenaar43d1ac62017-04-15 15:37:25 +020031silent! while 0
32 set nocompatible
33silent! endwhile
Bram Moolenaar33ccb242017-04-01 16:59:29 +020034
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020035" Allow backspacing over everything in insert mode.
36set backspace=indent,eol,start
37
38set history=200 " keep 200 lines of command line history
39set ruler " show the cursor position all the time
40set showcmd " display incomplete commands
41set wildmenu " display completion matches in a status line
42
Bram Moolenaare07e7972016-08-20 19:22:16 +020043set ttimeout " time out for key codes
44set ttimeoutlen=100 " wait up to 100ms after Esc for special key
45
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +020046" Show @@@ in the last line if it is truncated.
47set display=truncate
48
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020049" Show a few lines of context around the cursor. Note that this makes the
50" text scroll if you mouse-click near the start or end of the window.
Bram Moolenaar4427db92016-08-28 14:39:44 +020051set scrolloff=5
52
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020053" Do incremental searching when it's possible to timeout.
54if has('reltime')
55 set incsearch
56endif
57
58" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
59" confusing.
60set nrformats-=octal
61
62" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
63if has('win32')
64 set guioptions-=t
65endif
66
67" Don't use Ex mode, use Q for formatting.
68" Revert with ":unmap Q".
69map Q gq
70
71" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
72" so that you can undo CTRL-U after inserting a line break.
73" Revert with ":iunmap <C-U>".
74inoremap <C-U> <C-G>u<C-U>
75
76" In many terminal emulators the mouse works just fine. By enabling it you
77" can position the cursor, Visually select and scroll with the mouse.
78if has('mouse')
79 set mouse=a
80endif
81
82" Switch syntax highlighting on when the terminal has colors or when using the
83" GUI (which always has colors).
84if &t_Co > 2 || has("gui_running")
85 " Revert with ":syntax off".
86 syntax on
87
88 " I like highlighting strings inside C comments.
89 " Revert with ":unlet c_comment_strings".
90 let c_comment_strings=1
91endif
92
Bram Moolenaar314dd792019-02-03 15:27:20 +010093" Enable file type detection.
94" Use the default filetype settings, so that mail gets 'tw' set to 72,
95" 'cindent' is on in C files, etc.
96" Also load indent files, to automatically do language-dependent indenting.
97" Revert with ":filetype off".
98filetype plugin indent on
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020099
Bram Moolenaar314dd792019-02-03 15:27:20 +0100100" Put these in an autocmd group, so that you can revert them with:
101" ":augroup vimStartup | au! | augroup END"
102augroup vimStartup
103 au!
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200104
Bram Moolenaar314dd792019-02-03 15:27:20 +0100105 " When editing a file, always jump to the last known cursor position.
106 " Don't do it when the position is invalid, when inside an event handler
107 " (happens when dropping a file on gvim) and for a commit message (it's
108 " likely a different one than last time).
109 autocmd BufReadPost *
110 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
111 \ | exe "normal! g`\""
112 \ | endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200113
Bram Moolenaar314dd792019-02-03 15:27:20 +0100114augroup END
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200115
116" Convenient command to see the difference between the current buffer and the
117" file it was loaded from, thus the changes you made.
118" Only define it when not defined already.
119" Revert with: ":delcommand DiffOrig".
120if !exists(":DiffOrig")
121 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
122 \ | wincmd p | diffthis
123endif
124
Bram Moolenaar920694c2016-08-21 17:45:02 +0200125if has('langmap') && exists('+langremap')
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200126 " Prevent that the langmap option applies to characters that result from a
Bram Moolenaar920694c2016-08-21 17:45:02 +0200127 " mapping. If set (default), this may break plugins (but it's backward
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200128 " compatible).
Bram Moolenaar920694c2016-08-21 17:45:02 +0200129 set nolangremap
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200130endif