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