mswin.vim 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. " Set options and add mapping such that Vim behaves a lot like MS-Windows
  2. "
  3. " Maintainer: The Vim Project <https://github.com/vim/vim>
  4. " Last Change: 2024 Mar 13
  5. " Former Maintainer: Bram Moolenaar <Bram@vim.org>
  6. " Bail out if this isn't wanted.
  7. if exists("g:skip_loading_mswin") && g:skip_loading_mswin
  8. finish
  9. endif
  10. " set the 'cpoptions' to its Vim default
  11. if 1 " only do this when compiled with expression evaluation
  12. let s:save_cpo = &cpoptions
  13. endif
  14. set cpo&vim
  15. " set 'selection', 'selectmode', 'mousemodel' and 'keymodel' for MS-Windows
  16. set selection=exclusive
  17. set selectmode=mouse,key
  18. set mousemodel=popup
  19. set keymodel=startsel,stopsel
  20. " backspace and cursor keys wrap to previous/next line
  21. set backspace=indent,eol,start whichwrap+=<,>,[,]
  22. " backspace in Visual mode deletes selection
  23. vnoremap <BS> d
  24. " the better solution would be to use has("clipboard_working"),
  25. " but that may not be available yet while starting up, so let's just check if
  26. " clipboard support has been compiled in and assume it will be working :/
  27. if has("clipboard")
  28. " CTRL-X and SHIFT-Del are Cut
  29. vnoremap <C-X> "+x
  30. vnoremap <S-Del> "+x
  31. " CTRL-C and CTRL-Insert are Copy
  32. vnoremap <C-C> "+y
  33. vnoremap <C-Insert> "+y
  34. " CTRL-V and SHIFT-Insert are Paste
  35. map <C-V> "+gP
  36. map <S-Insert> "+gP
  37. cmap <C-V> <C-R>+
  38. cmap <S-Insert> <C-R>+
  39. else
  40. " Use the unnamed register when clipboard support not available
  41. " CTRL-X and SHIFT-Del are Cut
  42. vnoremap <C-X> x
  43. vnoremap <S-Del> x
  44. " CTRL-C and CTRL-Insert are Copy
  45. vnoremap <C-C> y
  46. vnoremap <C-Insert> y
  47. " CTRL-V and SHIFT-Insert are Paste
  48. noremap <C-V> gP
  49. noremap <S-Insert> gP
  50. inoremap <C-V> <C-R>"
  51. inoremap <S-Insert> <C-R>"
  52. endif
  53. " Pasting blockwise and linewise selections is not possible in Insert and
  54. " Visual mode without the +virtualedit feature. They are pasted as if they
  55. " were characterwise instead.
  56. " Uses the paste.vim autoload script.
  57. " Use CTRL-G u to have CTRL-Z only undo the paste.
  58. if has("clipboard")
  59. exe 'inoremap <script> <C-V> <C-G>u' . paste#paste_cmd['i']
  60. exe 'vnoremap <script> <C-V> ' . paste#paste_cmd['v']
  61. endif
  62. imap <S-Insert> <C-V>
  63. vmap <S-Insert> <C-V>
  64. " Use CTRL-Q to do what CTRL-V used to do
  65. noremap <C-Q> <C-V>
  66. " Use CTRL-S for saving, also in Insert mode (<C-O> doesn't work well when
  67. " using completions).
  68. noremap <C-S> :update<CR>
  69. vnoremap <C-S> <C-C>:update<CR>
  70. inoremap <C-S> <Esc>:update<CR>gi
  71. " For CTRL-V to work autoselect must be off.
  72. " On Unix we have two selections, autoselect can be used.
  73. if !has("unix")
  74. set guioptions-=a
  75. endif
  76. " CTRL-Z is Undo; not in cmdline though
  77. noremap <C-Z> u
  78. inoremap <C-Z> <C-O>u
  79. " CTRL-Y is Redo (although not repeat); not in cmdline though
  80. noremap <C-Y> <C-R>
  81. inoremap <C-Y> <C-O><C-R>
  82. " Alt-Space is System menu
  83. if has("gui")
  84. noremap <M-Space> :simalt ~<CR>
  85. inoremap <M-Space> <C-O>:simalt ~<CR>
  86. cnoremap <M-Space> <C-C>:simalt ~<CR>
  87. endif
  88. " CTRL-A is Select all
  89. noremap <C-A> gggH<C-O>G
  90. inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
  91. cnoremap <C-A> <C-C>gggH<C-O>G
  92. onoremap <C-A> <C-C>gggH<C-O>G
  93. snoremap <C-A> <C-C>gggH<C-O>G
  94. xnoremap <C-A> <C-C>ggVG
  95. " CTRL-Tab is Next window
  96. noremap <C-Tab> <C-W>w
  97. inoremap <C-Tab> <C-O><C-W>w
  98. cnoremap <C-Tab> <C-C><C-W>w
  99. onoremap <C-Tab> <C-C><C-W>w
  100. " CTRL-F4 is Close window
  101. noremap <C-F4> <C-W>c
  102. inoremap <C-F4> <C-O><C-W>c
  103. cnoremap <C-F4> <C-C><C-W>c
  104. onoremap <C-F4> <C-C><C-W>c
  105. if has("gui")
  106. " CTRL-F is the search dialog
  107. noremap <expr> <C-F> has("gui_running") ? ":promptfind\<CR>" : "/"
  108. inoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-O>:promptfind\<CR>" : "\<C-\>\<C-O>/"
  109. cnoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-C>:promptfind\<CR>" : "\<C-\>\<C-O>/"
  110. " CTRL-H is the replace dialog,
  111. " but in console, it might be backspace, so don't map it there
  112. nnoremap <expr> <C-H> has("gui_running") ? ":promptrepl\<CR>" : "\<C-H>"
  113. inoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-O>:promptrepl\<CR>" : "\<C-H>"
  114. cnoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-C>:promptrepl\<CR>" : "\<C-H>"
  115. endif
  116. " restore 'cpoptions'
  117. set cpo&
  118. if 1
  119. let &cpoptions = s:save_cpo
  120. unlet s:save_cpo
  121. endif