blob: 82f3358962e899332523f282609217ddf2ea22ad [file] [log] [blame]
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +02001" The default vimrc file.
2"
Christian Brabandte978b452023-08-13 10:33:05 +02003" Maintainer: The Vim Project <https://github.com/vim/vim>
Luca Saccarola437bc132024-11-14 21:21:17 +01004" Last Change: 2024 Nov 14
Christian Brabandte978b452023-08-13 10:33:05 +02005" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +02006"
7" This is loaded if no vimrc file was found.
8" Except when Vim is run with "-u NONE" or "-C".
9" Individual settings can be reverted with ":set option&".
10" Other commands can be reverted as mentioned below.
11
12" When started as "evim", evim.vim will already have done these settings.
13if v:progname =~? "evim"
14 finish
15endif
16
Bram Moolenaarb07a82b2016-09-03 20:08:56 +020017" Bail out if something that ran earlier, e.g. a system wide vimrc, does not
18" want Vim to use these default values.
19if exists('skip_defaults_vim')
20 finish
21endif
22
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020023" Use Vim settings, rather than Vi settings (much better!).
24" This must be first, because it changes other options as a side effect.
Bram Moolenaar0f39a822017-03-16 14:19:36 +010025" Avoid side effects when it was already reset.
26if &compatible
27 set nocompatible
28endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020029
Bram Moolenaar33ccb242017-04-01 16:59:29 +020030" When the +eval feature is missing, the set command above will be skipped.
31" Use a trick to reset compatible only when the +eval feature is missing.
Bram Moolenaar43d1ac62017-04-15 15:37:25 +020032silent! while 0
33 set nocompatible
34silent! endwhile
Bram Moolenaar33ccb242017-04-01 16:59:29 +020035
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020036" Allow backspacing over everything in insert mode.
37set backspace=indent,eol,start
38
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020039set ruler " show the cursor position all the time
40set showcmd " display incomplete commands
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020041
Bram Moolenaare07e7972016-08-20 19:22:16 +020042set ttimeout " time out for key codes
43set ttimeoutlen=100 " wait up to 100ms after Esc for special key
44
Bram Moolenaarb9a46fe2016-07-29 18:13:42 +020045" Show @@@ in the last line if it is truncated.
46set display=truncate
47
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020048" Show a few lines of context around the cursor. Note that this makes the
49" text scroll if you mouse-click near the start or end of the window.
Bram Moolenaar4427db92016-08-28 14:39:44 +020050set scrolloff=5
51
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020052" Do incremental searching when it's possible to timeout.
53if has('reltime')
54 set incsearch
55endif
56
57" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
58" confusing.
59set nrformats-=octal
60
61" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
62if has('win32')
63 set guioptions-=t
64endif
65
Bram Moolenaar1588bc82022-03-08 21:35:07 +000066" Don't use Q for Ex mode, use it for formatting. Except for Select mode.
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020067" Revert with ":unmap Q".
68map Q gq
Bram Moolenaar1588bc82022-03-08 21:35:07 +000069sunmap Q
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020070
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.
Bram Moolenaar5b418992019-10-27 18:50:25 +010078" Only xterm can grab the mouse events when using the shift key, for other
79" terminals use ":", select text and press Esc.
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020080if has('mouse')
Bram Moolenaar5b418992019-10-27 18:50:25 +010081 if &term =~ 'xterm'
82 set mouse=a
83 else
84 set mouse=nvi
85 endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020086endif
87
Bram Moolenaard53931a2019-02-18 21:32:28 +010088" Only do this part when Vim was compiled with the +eval feature.
89if 1
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020090
Bram Moolenaard53931a2019-02-18 21:32:28 +010091 " Enable file type detection.
92 " Use the default filetype settings, so that mail gets 'tw' set to 72,
93 " 'cindent' is on in C files, etc.
94 " Also load indent files, to automatically do language-dependent indenting.
95 " Revert with ":filetype off".
96 filetype plugin indent on
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +020097
Bram Moolenaard53931a2019-02-18 21:32:28 +010098 " Put these in an autocmd group, so that you can revert them with:
Balkic41b3c92023-07-14 16:59:40 +000099 " ":autocmd! vimStartup"
Bram Moolenaard53931a2019-02-18 21:32:28 +0100100 augroup vimStartup
Dragan Simic' via vim_dev81b8bf52023-08-09 17:23:58 +0200101 autocmd!
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200102
Bram Moolenaard53931a2019-02-18 21:32:28 +0100103 " When editing a file, always jump to the last known cursor position.
104 " Don't do it when the position is invalid, when inside an event handler
Dragan Simic' via vim_dev81b8bf52023-08-09 17:23:58 +0200105 " (happens when dropping a file on gvim), for a commit or rebase message
106 " (likely a different one than last time), and when using xxd(1) to filter
107 " and edit binary files (it transforms input files back and forth, causing
Yegappan Lakshmanana54816b2024-11-03 10:49:23 +0100108 " them to have dual nature, so to speak) or when running the new tutor
Bram Moolenaard53931a2019-02-18 21:32:28 +0100109 autocmd BufReadPost *
Dragan Simic' via vim_dev81b8bf52023-08-09 17:23:58 +0200110 \ let line = line("'\"")
111 \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
Yegappan Lakshmanana54816b2024-11-03 10:49:23 +0100112 \ && index(['xxd', 'gitrebase', 'tutor'], &filetype) == -1
Dragan Simic' via vim_dev81b8bf52023-08-09 17:23:58 +0200113 \ | execute "normal! g`\""
Bram Moolenaard53931a2019-02-18 21:32:28 +0100114 \ | endif
115
h-east624bb832024-11-09 18:37:32 +0100116 " Set the default background for putty to dark. Putty usually sets the
Christian Brabandt2abec432024-10-27 21:33:09 +0100117 " $TERM to xterm and by default it starts with a dark background which
118 " makes syntax highlighting often hard to read with bg=light
119 " undo this using: ":au! vimStartup TermResponse"
120 autocmd TermResponse * if v:termresponse == "\e[>0;136;0c" | set bg=dark | endif
Bram Moolenaard53931a2019-02-18 21:32:28 +0100121 augroup END
122
Egor Zvorykin125ffd22021-11-17 14:01:14 +0000123 " Quite a few people accidentally type "q:" instead of ":q" and get confused
124 " by the command line window. Give a hint about how to get out.
125 " If you don't like this you can put this in your vimrc:
Balkic41b3c92023-07-14 16:59:40 +0000126 " ":autocmd! vimHints"
Egor Zvorykin125ffd22021-11-17 14:01:14 +0000127 augroup vimHints
Bram Moolenaar88a42052021-11-21 21:13:36 +0000128 au!
129 autocmd CmdwinEnter *
Dragan Simic' via vim_dev81b8bf52023-08-09 17:23:58 +0200130 \ echohl Todo |
Bram Moolenaar65b34862023-05-10 14:47:50 +0100131 \ echo gettext('You discovered the command-line window! You can close it with ":q".') |
Egor Zvorykin125ffd22021-11-17 14:01:14 +0000132 \ echohl None
133 augroup END
134
Bram Moolenaard53931a2019-02-18 21:32:28 +0100135endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200136
Bram Moolenaar17bb4d42020-09-30 22:45:39 +0200137" Switch syntax highlighting on when the terminal has colors or when using the
138" GUI (which always has colors).
139if &t_Co > 2 || has("gui_running")
140 " Revert with ":syntax off".
141 syntax on
142
143 " I like highlighting strings inside C comments.
144 " Revert with ":unlet c_comment_strings".
145 let c_comment_strings=1
146endif
147
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200148" Convenient command to see the difference between the current buffer and the
149" file it was loaded from, thus the changes you made.
150" Only define it when not defined already.
151" Revert with: ":delcommand DiffOrig".
152if !exists(":DiffOrig")
153 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
154 \ | wincmd p | diffthis
155endif
156
Bram Moolenaar920694c2016-08-21 17:45:02 +0200157if has('langmap') && exists('+langremap')
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200158 " Prevent that the langmap option applies to characters that result from a
Bram Moolenaar920694c2016-08-21 17:45:02 +0200159 " mapping. If set (default), this may break plugins (but it's backward
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200160 " compatible).
Bram Moolenaar920694c2016-08-21 17:45:02 +0200161 set nolangremap
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200162endif