blob: 1c28cadac0e1f747b5d4521cbf309fc6a5e436f8 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Set options and add mapping such that Vim behaves a lot like MS-Windows
2"
Christian Brabandte978b452023-08-13 10:33:05 +02003" Maintainer: The Vim Project <https://github.com/vim/vim>
4" Last Change: 2023 Aug 10
5" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar269ec652004-07-29 08:43:53 +00006
Bram Moolenaard47d5222018-12-09 20:43:55 +01007" Bail out if this isn't wanted.
Bram Moolenaar269ec652004-07-29 08:43:53 +00008if exists("g:skip_loading_mswin") && g:skip_loading_mswin
9 finish
10endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
12" set the 'cpoptions' to its Vim default
13if 1 " only do this when compiled with expression evaluation
14 let s:save_cpo = &cpoptions
15endif
16set cpo&vim
17
18" set 'selection', 'selectmode', 'mousemodel' and 'keymodel' for MS-Windows
19behave mswin
20
21" backspace and cursor keys wrap to previous/next line
22set backspace=indent,eol,start whichwrap+=<,>,[,]
23
24" backspace in Visual mode deletes selection
25vnoremap <BS> d
26
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010027if has("clipboard")
28 " CTRL-X and SHIFT-Del are Cut
29 vnoremap <C-X> "+x
30 vnoremap <S-Del> "+x
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010032 " CTRL-C and CTRL-Insert are Copy
33 vnoremap <C-C> "+y
34 vnoremap <C-Insert> "+y
Bram Moolenaar071d4272004-06-13 20:20:40 +000035
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010036 " CTRL-V and SHIFT-Insert are Paste
37 map <C-V> "+gP
38 map <S-Insert> "+gP
Bram Moolenaar071d4272004-06-13 20:20:40 +000039
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010040 cmap <C-V> <C-R>+
41 cmap <S-Insert> <C-R>+
42endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
44" Pasting blockwise and linewise selections is not possible in Insert and
45" Visual mode without the +virtualedit feature. They are pasted as if they
46" were characterwise instead.
Bram Moolenaar1056d982006-03-09 22:37:52 +000047" Uses the paste.vim autoload script.
Bram Moolenaar30b65812012-07-12 22:01:11 +020048" Use CTRL-G u to have CTRL-Z only undo the paste.
Bram Moolenaar1056d982006-03-09 22:37:52 +000049
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010050if 1
51 exe 'inoremap <script> <C-V> <C-G>u' . paste#paste_cmd['i']
52 exe 'vnoremap <script> <C-V> ' . paste#paste_cmd['v']
53endif
Bram Moolenaar1056d982006-03-09 22:37:52 +000054
Bram Moolenaar071d4272004-06-13 20:20:40 +000055imap <S-Insert> <C-V>
56vmap <S-Insert> <C-V>
57
58" Use CTRL-Q to do what CTRL-V used to do
59noremap <C-Q> <C-V>
60
Bram Moolenaara9604e62018-07-21 05:56:22 +020061" Use CTRL-S for saving, also in Insert mode (<C-O> doesn't work well when
62" using completions).
Bram Moolenaar071d4272004-06-13 20:20:40 +000063noremap <C-S> :update<CR>
64vnoremap <C-S> <C-C>:update<CR>
Bram Moolenaara9604e62018-07-21 05:56:22 +020065inoremap <C-S> <Esc>:update<CR>gi
Bram Moolenaar071d4272004-06-13 20:20:40 +000066
67" For CTRL-V to work autoselect must be off.
68" On Unix we have two selections, autoselect can be used.
69if !has("unix")
70 set guioptions-=a
71endif
72
73" CTRL-Z is Undo; not in cmdline though
74noremap <C-Z> u
75inoremap <C-Z> <C-O>u
76
77" CTRL-Y is Redo (although not repeat); not in cmdline though
78noremap <C-Y> <C-R>
79inoremap <C-Y> <C-O><C-R>
80
81" Alt-Space is System menu
82if has("gui")
83 noremap <M-Space> :simalt ~<CR>
84 inoremap <M-Space> <C-O>:simalt ~<CR>
85 cnoremap <M-Space> <C-C>:simalt ~<CR>
86endif
87
88" CTRL-A is Select all
89noremap <C-A> gggH<C-O>G
90inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
91cnoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaard2cec5b2006-03-28 21:08:56 +000092onoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaar910f66f2006-04-05 20:41:53 +000093snoremap <C-A> <C-C>gggH<C-O>G
94xnoremap <C-A> <C-C>ggVG
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96" CTRL-Tab is Next window
97noremap <C-Tab> <C-W>w
98inoremap <C-Tab> <C-O><C-W>w
99cnoremap <C-Tab> <C-C><C-W>w
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000100onoremap <C-Tab> <C-C><C-W>w
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
102" CTRL-F4 is Close window
103noremap <C-F4> <C-W>c
104inoremap <C-F4> <C-O><C-W>c
105cnoremap <C-F4> <C-C><C-W>c
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000106onoremap <C-F4> <C-C><C-W>c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100108if has("gui")
109 " CTRL-F is the search dialog
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200110 noremap <expr> <C-F> has("gui_running") ? ":promptfind\<CR>" : "/"
111 inoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-O>:promptfind\<CR>" : "\<C-\>\<C-O>/"
112 cnoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-C>:promptfind\<CR>" : "\<C-\>\<C-O>/"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100113
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200114 " CTRL-H is the replace dialog,
115 " but in console, it might be backspace, so don't map it there
116 nnoremap <expr> <C-H> has("gui_running") ? ":promptrepl\<CR>" : "\<C-H>"
117 inoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-O>:promptrepl\<CR>" : "\<C-H>"
118 cnoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-C>:promptrepl\<CR>" : "\<C-H>"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100119endif
120
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121" restore 'cpoptions'
122set cpo&
123if 1
124 let &cpoptions = s:save_cpo
125 unlet s:save_cpo
126endif