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