blob: da869a9fc745101a6cfd39669ab5e4e1654f6c7c [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 Moolenaarc3fdf7f2017-10-28 18:36:48 +02004" Last change: 2017 Oct 28
Bram Moolenaar269ec652004-07-29 08:43:53 +00005
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
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
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +000090onoremap <C-A> <C-C>gggH<C-O>G
Bram Moolenaar910f66f2006-04-05 20:41:53 +000091snoremap <C-A> <C-C>gggH<C-O>G
92xnoremap <C-A> <C-C>ggVG
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +000098onoremap <C-Tab> <C-C><C-W>w
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
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
Bram Moolenaard2cec5b2006-03-28 21:08:56 +0000104onoremap <C-F4> <C-C><C-W>c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100106if has("gui")
107 " CTRL-F is the search dialog
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200108 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>/"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100111
Bram Moolenaarc3fdf7f2017-10-28 18:36:48 +0200112 " 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>"
Bram Moolenaar8cc2a9c2017-02-09 20:22:30 +0100117endif
118
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119" restore 'cpoptions'
120set cpo&
121if 1
122 let &cpoptions = s:save_cpo
123 unlet s:save_cpo
124endif