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