Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 1 | " The default vimrc file. |
| 2 | " |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 3 | " Maintainer: The Vim Project <https://github.com/vim/vim> |
Yegappan Lakshmanan | a54816b | 2024-11-03 10:49:23 +0100 | [diff] [blame] | 4 | " Last Change: 2024 Nov 03 |
Christian Brabandt | e978b45 | 2023-08-13 10:33:05 +0200 | [diff] [blame] | 5 | " Former Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 6 | " |
| 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. |
| 13 | if v:progname =~? "evim" |
| 14 | finish |
| 15 | endif |
| 16 | |
Bram Moolenaar | b07a82b | 2016-09-03 20:08:56 +0200 | [diff] [blame] | 17 | " Bail out if something that ran earlier, e.g. a system wide vimrc, does not |
| 18 | " want Vim to use these default values. |
| 19 | if exists('skip_defaults_vim') |
| 20 | finish |
| 21 | endif |
| 22 | |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 23 | " Use Vim settings, rather than Vi settings (much better!). |
| 24 | " This must be first, because it changes other options as a side effect. |
Bram Moolenaar | 0f39a82 | 2017-03-16 14:19:36 +0100 | [diff] [blame] | 25 | " Avoid side effects when it was already reset. |
| 26 | if &compatible |
| 27 | set nocompatible |
| 28 | endif |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 29 | |
Bram Moolenaar | 33ccb24 | 2017-04-01 16:59:29 +0200 | [diff] [blame] | 30 | " 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 Moolenaar | 43d1ac6 | 2017-04-15 15:37:25 +0200 | [diff] [blame] | 32 | silent! while 0 |
| 33 | set nocompatible |
| 34 | silent! endwhile |
Bram Moolenaar | 33ccb24 | 2017-04-01 16:59:29 +0200 | [diff] [blame] | 35 | |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 36 | " Allow backspacing over everything in insert mode. |
| 37 | set backspace=indent,eol,start |
| 38 | |
| 39 | set history=200 " keep 200 lines of command line history |
| 40 | set ruler " show the cursor position all the time |
| 41 | set showcmd " display incomplete commands |
| 42 | set wildmenu " display completion matches in a status line |
| 43 | |
Bram Moolenaar | e07e797 | 2016-08-20 19:22:16 +0200 | [diff] [blame] | 44 | set ttimeout " time out for key codes |
| 45 | set ttimeoutlen=100 " wait up to 100ms after Esc for special key |
| 46 | |
Bram Moolenaar | b9a46fe | 2016-07-29 18:13:42 +0200 | [diff] [blame] | 47 | " Show @@@ in the last line if it is truncated. |
| 48 | set display=truncate |
| 49 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 50 | " Show a few lines of context around the cursor. Note that this makes the |
| 51 | " text scroll if you mouse-click near the start or end of the window. |
Bram Moolenaar | 4427db9 | 2016-08-28 14:39:44 +0200 | [diff] [blame] | 52 | set scrolloff=5 |
| 53 | |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 54 | " Do incremental searching when it's possible to timeout. |
| 55 | if has('reltime') |
| 56 | set incsearch |
| 57 | endif |
| 58 | |
| 59 | " Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it |
| 60 | " confusing. |
| 61 | set nrformats-=octal |
| 62 | |
| 63 | " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries. |
| 64 | if has('win32') |
| 65 | set guioptions-=t |
| 66 | endif |
| 67 | |
Bram Moolenaar | 1588bc8 | 2022-03-08 21:35:07 +0000 | [diff] [blame] | 68 | " Don't use Q for Ex mode, use it for formatting. Except for Select mode. |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 69 | " Revert with ":unmap Q". |
| 70 | map Q gq |
Bram Moolenaar | 1588bc8 | 2022-03-08 21:35:07 +0000 | [diff] [blame] | 71 | sunmap Q |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 72 | |
| 73 | " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, |
| 74 | " so that you can undo CTRL-U after inserting a line break. |
| 75 | " Revert with ":iunmap <C-U>". |
| 76 | inoremap <C-U> <C-G>u<C-U> |
| 77 | |
| 78 | " In many terminal emulators the mouse works just fine. By enabling it you |
| 79 | " can position the cursor, Visually select and scroll with the mouse. |
Bram Moolenaar | 5b41899 | 2019-10-27 18:50:25 +0100 | [diff] [blame] | 80 | " Only xterm can grab the mouse events when using the shift key, for other |
| 81 | " terminals use ":", select text and press Esc. |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 82 | if has('mouse') |
Bram Moolenaar | 5b41899 | 2019-10-27 18:50:25 +0100 | [diff] [blame] | 83 | if &term =~ 'xterm' |
| 84 | set mouse=a |
| 85 | else |
| 86 | set mouse=nvi |
| 87 | endif |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 88 | endif |
| 89 | |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 90 | " Only do this part when Vim was compiled with the +eval feature. |
| 91 | if 1 |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 92 | |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 93 | " 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". |
| 98 | filetype plugin indent on |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 99 | |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 100 | " Put these in an autocmd group, so that you can revert them with: |
Balki | c41b3c9 | 2023-07-14 16:59:40 +0000 | [diff] [blame] | 101 | " ":autocmd! vimStartup" |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 102 | augroup vimStartup |
Dragan Simic' via vim_dev | 81b8bf5 | 2023-08-09 17:23:58 +0200 | [diff] [blame] | 103 | autocmd! |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 104 | |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 105 | " 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 |
Dragan Simic' via vim_dev | 81b8bf5 | 2023-08-09 17:23:58 +0200 | [diff] [blame] | 107 | " (happens when dropping a file on gvim), for a commit or rebase message |
| 108 | " (likely a different one than last time), and when using xxd(1) to filter |
| 109 | " and edit binary files (it transforms input files back and forth, causing |
Yegappan Lakshmanan | a54816b | 2024-11-03 10:49:23 +0100 | [diff] [blame] | 110 | " them to have dual nature, so to speak) or when running the new tutor |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 111 | autocmd BufReadPost * |
Dragan Simic' via vim_dev | 81b8bf5 | 2023-08-09 17:23:58 +0200 | [diff] [blame] | 112 | \ let line = line("'\"") |
| 113 | \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit' |
Yegappan Lakshmanan | a54816b | 2024-11-03 10:49:23 +0100 | [diff] [blame] | 114 | \ && index(['xxd', 'gitrebase', 'tutor'], &filetype) == -1 |
Dragan Simic' via vim_dev | 81b8bf5 | 2023-08-09 17:23:58 +0200 | [diff] [blame] | 115 | \ | execute "normal! g`\"" |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 116 | \ | endif |
| 117 | |
Christian Brabandt | 2abec43 | 2024-10-27 21:33:09 +0100 | [diff] [blame] | 118 | " Set the default background for putty to dark. Putty usually sets the |
| 119 | " $TERM to xterm and by default it starts with a dark background which |
| 120 | " makes syntax highlighting often hard to read with bg=light |
| 121 | " undo this using: ":au! vimStartup TermResponse" |
| 122 | autocmd TermResponse * if v:termresponse == "\e[>0;136;0c" | set bg=dark | endif |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 123 | augroup END |
| 124 | |
Egor Zvorykin | 125ffd2 | 2021-11-17 14:01:14 +0000 | [diff] [blame] | 125 | " Quite a few people accidentally type "q:" instead of ":q" and get confused |
| 126 | " by the command line window. Give a hint about how to get out. |
| 127 | " If you don't like this you can put this in your vimrc: |
Balki | c41b3c9 | 2023-07-14 16:59:40 +0000 | [diff] [blame] | 128 | " ":autocmd! vimHints" |
Egor Zvorykin | 125ffd2 | 2021-11-17 14:01:14 +0000 | [diff] [blame] | 129 | augroup vimHints |
Bram Moolenaar | 88a4205 | 2021-11-21 21:13:36 +0000 | [diff] [blame] | 130 | au! |
| 131 | autocmd CmdwinEnter * |
Dragan Simic' via vim_dev | 81b8bf5 | 2023-08-09 17:23:58 +0200 | [diff] [blame] | 132 | \ echohl Todo | |
Bram Moolenaar | 65b3486 | 2023-05-10 14:47:50 +0100 | [diff] [blame] | 133 | \ echo gettext('You discovered the command-line window! You can close it with ":q".') | |
Egor Zvorykin | 125ffd2 | 2021-11-17 14:01:14 +0000 | [diff] [blame] | 134 | \ echohl None |
| 135 | augroup END |
| 136 | |
Bram Moolenaar | d53931a | 2019-02-18 21:32:28 +0100 | [diff] [blame] | 137 | endif |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 138 | |
Bram Moolenaar | 17bb4d4 | 2020-09-30 22:45:39 +0200 | [diff] [blame] | 139 | " Switch syntax highlighting on when the terminal has colors or when using the |
| 140 | " GUI (which always has colors). |
| 141 | if &t_Co > 2 || has("gui_running") |
| 142 | " Revert with ":syntax off". |
| 143 | syntax on |
| 144 | |
| 145 | " I like highlighting strings inside C comments. |
| 146 | " Revert with ":unlet c_comment_strings". |
| 147 | let c_comment_strings=1 |
| 148 | endif |
| 149 | |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 150 | " Convenient command to see the difference between the current buffer and the |
| 151 | " file it was loaded from, thus the changes you made. |
| 152 | " Only define it when not defined already. |
| 153 | " Revert with: ":delcommand DiffOrig". |
| 154 | if !exists(":DiffOrig") |
| 155 | command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis |
| 156 | \ | wincmd p | diffthis |
| 157 | endif |
| 158 | |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 159 | if has('langmap') && exists('+langremap') |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 160 | " Prevent that the langmap option applies to characters that result from a |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 161 | " mapping. If set (default), this may break plugins (but it's backward |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 162 | " compatible). |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 163 | set nolangremap |
Bram Moolenaar | 8c08b5b | 2016-07-28 22:24:15 +0200 | [diff] [blame] | 164 | endif |