defaults.vim 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. " The default vimrc file.
  2. "
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last change: 2022 Mar 03
  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. " When started as "evim", evim.vim will already have done these settings.
  11. if v:progname =~? "evim"
  12. finish
  13. endif
  14. " Bail out if something that ran earlier, e.g. a system wide vimrc, does not
  15. " want Vim to use these default values.
  16. if exists('skip_defaults_vim')
  17. finish
  18. endif
  19. " Use Vim settings, rather than Vi settings (much better!).
  20. " This must be first, because it changes other options as a side effect.
  21. " Avoid side effects when it was already reset.
  22. if &compatible
  23. set nocompatible
  24. endif
  25. " When the +eval feature is missing, the set command above will be skipped.
  26. " Use a trick to reset compatible only when the +eval feature is missing.
  27. silent! while 0
  28. set nocompatible
  29. silent! endwhile
  30. " Allow backspacing over everything in insert mode.
  31. set backspace=indent,eol,start
  32. set history=200 " keep 200 lines of command line history
  33. set ruler " show the cursor position all the time
  34. set showcmd " display incomplete commands
  35. set wildmenu " display completion matches in a status line
  36. set ttimeout " time out for key codes
  37. set ttimeoutlen=100 " wait up to 100ms after Esc for special key
  38. " Show @@@ in the last line if it is truncated.
  39. set display=truncate
  40. " Show a few lines of context around the cursor. Note that this makes the
  41. " text scroll if you mouse-click near the start or end of the window.
  42. set scrolloff=5
  43. " Do incremental searching when it's possible to timeout.
  44. if has('reltime')
  45. set incsearch
  46. endif
  47. " Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it
  48. " confusing.
  49. set nrformats-=octal
  50. " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries.
  51. if has('win32')
  52. set guioptions-=t
  53. endif
  54. " Don't use Q for Ex mode, use it for formatting. Except for Select mode.
  55. " Revert with ":unmap Q".
  56. map Q gq
  57. sunmap Q
  58. " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
  59. " so that you can undo CTRL-U after inserting a line break.
  60. " Revert with ":iunmap <C-U>".
  61. inoremap <C-U> <C-G>u<C-U>
  62. " In many terminal emulators the mouse works just fine. By enabling it you
  63. " can position the cursor, Visually select and scroll with the mouse.
  64. " Only xterm can grab the mouse events when using the shift key, for other
  65. " terminals use ":", select text and press Esc.
  66. if has('mouse')
  67. if &term =~ 'xterm'
  68. set mouse=a
  69. else
  70. set mouse=nvi
  71. endif
  72. endif
  73. " Only do this part when Vim was compiled with the +eval feature.
  74. if 1
  75. " Enable file type detection.
  76. " Use the default filetype settings, so that mail gets 'tw' set to 72,
  77. " 'cindent' is on in C files, etc.
  78. " Also load indent files, to automatically do language-dependent indenting.
  79. " Revert with ":filetype off".
  80. filetype plugin indent on
  81. " Put these in an autocmd group, so that you can revert them with:
  82. " ":augroup vimStartup | exe 'au!' | augroup END"
  83. augroup vimStartup
  84. au!
  85. " When editing a file, always jump to the last known cursor position.
  86. " Don't do it when the position is invalid, when inside an event handler
  87. " (happens when dropping a file on gvim) and for a commit message (it's
  88. " likely a different one than last time).
  89. autocmd BufReadPost *
  90. \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
  91. \ | exe "normal! g`\""
  92. \ | endif
  93. augroup END
  94. " Quite a few people accidentally type "q:" instead of ":q" and get confused
  95. " by the command line window. Give a hint about how to get out.
  96. " If you don't like this you can put this in your vimrc:
  97. " ":augroup vimHints | exe 'au!' | augroup END"
  98. augroup vimHints
  99. au!
  100. autocmd CmdwinEnter *
  101. \ echohl Todo |
  102. \ echo 'You discovered the command-line window! You can close it with ":q".' |
  103. \ echohl None
  104. augroup END
  105. endif
  106. " Switch syntax highlighting on when the terminal has colors or when using the
  107. " GUI (which always has colors).
  108. if &t_Co > 2 || has("gui_running")
  109. " Revert with ":syntax off".
  110. syntax on
  111. " I like highlighting strings inside C comments.
  112. " Revert with ":unlet c_comment_strings".
  113. let c_comment_strings=1
  114. endif
  115. " Convenient command to see the difference between the current buffer and the
  116. " file it was loaded from, thus the changes you made.
  117. " Only define it when not defined already.
  118. " Revert with: ":delcommand DiffOrig".
  119. if !exists(":DiffOrig")
  120. command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
  121. \ | wincmd p | diffthis
  122. endif
  123. if has('langmap') && exists('+langremap')
  124. " Prevent that the langmap option applies to characters that result from a
  125. " mapping. If set (default), this may break plugins (but it's backward
  126. " compatible).
  127. set nolangremap
  128. endif