xref: /vim-8.2.3635/runtime/mswin.vim (revision 8ee2d36e)
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:	2017 Oct 28
5
6" bail out if this isn't wanted (mrsvim.vim uses this).
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
61noremap <C-S>		:update<CR>
62vnoremap <C-S>		<C-C>:update<CR>
63inoremap <C-S>		<C-O>:update<CR>
64
65" For CTRL-V to work autoselect must be off.
66" On Unix we have two selections, autoselect can be used.
67if !has("unix")
68  set guioptions-=a
69endif
70
71" CTRL-Z is Undo; not in cmdline though
72noremap <C-Z> u
73inoremap <C-Z> <C-O>u
74
75" CTRL-Y is Redo (although not repeat); not in cmdline though
76noremap <C-Y> <C-R>
77inoremap <C-Y> <C-O><C-R>
78
79" Alt-Space is System menu
80if has("gui")
81  noremap <M-Space> :simalt ~<CR>
82  inoremap <M-Space> <C-O>:simalt ~<CR>
83  cnoremap <M-Space> <C-C>:simalt ~<CR>
84endif
85
86" CTRL-A is Select all
87noremap <C-A> gggH<C-O>G
88inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
89cnoremap <C-A> <C-C>gggH<C-O>G
90onoremap <C-A> <C-C>gggH<C-O>G
91snoremap <C-A> <C-C>gggH<C-O>G
92xnoremap <C-A> <C-C>ggVG
93
94" CTRL-Tab is Next window
95noremap <C-Tab> <C-W>w
96inoremap <C-Tab> <C-O><C-W>w
97cnoremap <C-Tab> <C-C><C-W>w
98onoremap <C-Tab> <C-C><C-W>w
99
100" CTRL-F4 is Close window
101noremap <C-F4> <C-W>c
102inoremap <C-F4> <C-O><C-W>c
103cnoremap <C-F4> <C-C><C-W>c
104onoremap <C-F4> <C-C><C-W>c
105
106if has("gui")
107  " CTRL-F is the search dialog
108  noremap  <expr> <C-F> has("gui_running") ? ":promptfind\<CR>" : "/"
109  inoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-O>:promptfind\<CR>" : "\<C-\>\<C-O>/"
110  cnoremap <expr> <C-F> has("gui_running") ? "\<C-\>\<C-C>:promptfind\<CR>" : "\<C-\>\<C-O>/"
111
112  " CTRL-H is the replace dialog,
113  " but in console, it might be backspace, so don't map it there
114  nnoremap <expr> <C-H> has("gui_running") ? ":promptrepl\<CR>" : "\<C-H>"
115  inoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-O>:promptrepl\<CR>" : "\<C-H>"
116  cnoremap <expr> <C-H> has("gui_running") ? "\<C-\>\<C-C>:promptrepl\<CR>" : "\<C-H>"
117endif
118
119" restore 'cpoptions'
120set cpo&
121if 1
122  let &cpoptions = s:save_cpo
123  unlet s:save_cpo
124endif
125