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