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