blob: 798d94061c1aafecc11a054ef835b5b45f4aa2be [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>
Christian Brabandt760f6642024-03-13 16:38:16 +01004" Last Change: 2024 Mar 13
Christian Brabandte978b452023-08-13 10:33:05 +02005" 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
Christian Brabandt760f6642024-03-13 16:38:16 +010027" the better solution would be to use has("clipboard_working"),
28" but that may not be available yet while starting up, so let's just check if
29" clipboard support has been compiled in and assume it will be working :/
30if has("clipboard")
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010031 " CTRL-X and SHIFT-Del are Cut
32 vnoremap <C-X> "+x
33 vnoremap <S-Del> "+x
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010035 " CTRL-C and CTRL-Insert are Copy
36 vnoremap <C-C> "+y
37 vnoremap <C-Insert> "+y
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010039 " CTRL-V and SHIFT-Insert are Paste
40 map <C-V> "+gP
41 map <S-Insert> "+gP
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010043 cmap <C-V> <C-R>+
44 cmap <S-Insert> <C-R>+
Shixian Lid9ebd462024-03-03 23:41:46 +080045else
Christian Brabandt760f6642024-03-13 16:38:16 +010046 " Use the unnamed register when clipboard support not available
Shixian Lid9ebd462024-03-03 23:41:46 +080047
48 " CTRL-X and SHIFT-Del are Cut
49 vnoremap <C-X> x
50 vnoremap <S-Del> x
51
52 " CTRL-C and CTRL-Insert are Copy
53 vnoremap <C-C> y
54 vnoremap <C-Insert> y
55
56 " CTRL-V and SHIFT-Insert are Paste
57 noremap <C-V> gP
58 noremap <S-Insert> gP
59
60 inoremap <C-V> <C-R>"
61 inoremap <S-Insert> <C-R>"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010062endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
64" Pasting blockwise and linewise selections is not possible in Insert and
65" Visual mode without the +virtualedit feature. They are pasted as if they
66" were characterwise instead.
Bram Moolenaar1056d982006-03-09 22:37:52 +000067" Uses the paste.vim autoload script.
Bram Moolenaar30b65812012-07-12 22:01:11 +020068" Use CTRL-G u to have CTRL-Z only undo the paste.
Bram Moolenaar1056d982006-03-09 22:37:52 +000069
Shixian Lid9ebd462024-03-03 23:41:46 +080070if has("clipboard_working")
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010071 exe 'inoremap <script> <C-V> <C-G>u' . paste#paste_cmd['i']
72 exe 'vnoremap <script> <C-V> ' . paste#paste_cmd['v']
73endif
Bram Moolenaar1056d982006-03-09 22:37:52 +000074
Bram Moolenaar071d4272004-06-13 20:20:40 +000075imap <S-Insert> <C-V>
76vmap <S-Insert> <C-V>
77
78" Use CTRL-Q to do what CTRL-V used to do
79noremap <C-Q> <C-V>
80
Bram Moolenaara9604e62018-07-21 05:56:22 +020081" Use CTRL-S for saving, also in Insert mode (<C-O> doesn't work well when
82" using completions).
Bram Moolenaar071d4272004-06-13 20:20:40 +000083noremap <C-S> :update<CR>
84vnoremap <C-S> <C-C>:update<CR>
Bram Moolenaara9604e62018-07-21 05:56:22 +020085inoremap <C-S> <Esc>:update<CR>gi
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
87" For CTRL-V to work autoselect must be off.
88" On Unix we have two selections, autoselect can be used.
89if !has("unix")
90 set guioptions-=a
91endif
92
93" CTRL-Z is Undo; not in cmdline though
94noremap <C-Z> u
95inoremap <C-Z> <C-O>u
96
97" CTRL-Y is Redo (although not repeat); not in cmdline though
98noremap <C-Y> <C-R>
99inoremap <C-Y> <C-O><C-R>
100
101" Alt-Space is System menu
102if has("gui")
103 noremap <M-Space> :simalt ~<CR>
104 inoremap <M-Space> <C-O>:simalt ~<CR>
105 cnoremap <M-Space> <C-C>:simalt ~<CR>
106endif
107
108" CTRL-A is Select all
109noremap <C-A> gggH<C-O>G
110inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
111cnoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000112onoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000113snoremap <C-A> <C-C>gggH<C-O>G
114xnoremap <C-A> <C-C>ggVG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115
116" CTRL-Tab is Next window
117noremap <C-Tab> <C-W>w
118inoremap <C-Tab> <C-O><C-W>w
119cnoremap <C-Tab> <C-C><C-W>w
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000120onoremap <C-Tab> <C-C><C-W>w
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
122" CTRL-F4 is Close window
123noremap <C-F4> <C-W>c
124inoremap <C-F4> <C-O><C-W>c
125cnoremap <C-F4> <C-C><C-W>c
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000126onoremap <C-F4> <C-C><C-W>c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100128if has("gui")
129 " CTRL-F is the search dialog
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200130 noremap <expr> <C-F> has("gui_running") ? ":promptfind\<CR>" : "/"
131 inoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-O>:promptfind\<CR>" : "\<C-\>\<C-O>/"
132 cnoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-C>:promptfind\<CR>" : "\<C-\>\<C-O>/"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100133
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200134 " CTRL-H is the replace dialog,
135 " but in console, it might be backspace, so don't map it there
136 nnoremap <expr> <C-H> has("gui_running") ? ":promptrepl\<CR>" : "\<C-H>"
137 inoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-O>:promptrepl\<CR>" : "\<C-H>"
138 cnoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-C>:promptrepl\<CR>" : "\<C-H>"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100139endif
140
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141" restore 'cpoptions'
142set cpo&
143if 1
144 let &cpoptions = s:save_cpo
145 unlet s:save_cpo
146endif