mswin.vim 3.3 KB

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