blob: 2b04c1aea3d2482c1979928504c39dcba962ce27 [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"
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaard47d5222018-12-09 20:43:55 +01004" Last Change: 2018 Dec 07
Bram Moolenaar269ec652004-07-29 08:43:53 +00005
Bram Moolenaard47d5222018-12-09 20:43:55 +01006" Bail out if this isn't wanted.
Bram Moolenaar269ec652004-07-29 08:43:53 +00007if exists("g:skip_loading_mswin") && g:skip_loading_mswin
8 finish
9endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
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
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010026if has("clipboard")
27 " CTRL-X and SHIFT-Del are Cut
28 vnoremap <C-X> "+x
29 vnoremap <S-Del> "+x
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010031 " CTRL-C and CTRL-Insert are Copy
32 vnoremap <C-C> "+y
33 vnoremap <C-Insert> "+y
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010035 " CTRL-V and SHIFT-Insert are Paste
36 map <C-V> "+gP
37 map <S-Insert> "+gP
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010039 cmap <C-V> <C-R>+
40 cmap <S-Insert> <C-R>+
41endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
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.
Bram Moolenaar1056d982006-03-09 22:37:52 +000046" Uses the paste.vim autoload script.
Bram Moolenaar30b65812012-07-12 22:01:11 +020047" Use CTRL-G u to have CTRL-Z only undo the paste.
Bram Moolenaar1056d982006-03-09 22:37:52 +000048
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +010049if 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
Bram Moolenaar1056d982006-03-09 22:37:52 +000053
Bram Moolenaar071d4272004-06-13 20:20:40 +000054imap <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
Bram Moolenaara9604e62018-07-21 05:56:22 +020060" Use CTRL-S for saving, also in Insert mode (<C-O> doesn't work well when
61" using completions).
Bram Moolenaar071d4272004-06-13 20:20:40 +000062noremap <C-S> :update<CR>
63vnoremap <C-S> <C-C>:update<CR>
Bram Moolenaara9604e62018-07-21 05:56:22 +020064inoremap <C-S> <Esc>:update<CR>gi
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +000091onoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaar910f66f2006-04-05 20:41:53 +000092snoremap <C-A> <C-C>gggH<C-O>G
93xnoremap <C-A> <C-C>ggVG
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +000099onoremap <C-Tab> <C-C><C-W>w
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000105onoremap <C-F4> <C-C><C-W>c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100107if has("gui")
108 " CTRL-F is the search dialog
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200109 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>/"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100112
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200113 " 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>"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100118endif
119
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120" restore 'cpoptions'
121set cpo&
122if 1
123 let &cpoptions = s:save_cpo
124 unlet s:save_cpo
125endif