Skip to content

Commit c3fdf7f

Browse files
committed
patch 8.0.1232: MS-Windows users are confused about default mappings
Problem: MS-Windows users are confused about default mappings. Solution: Don't map keys in the console where they don't work. Add a choice in the installer to use MS-Windows key bindings or not. (Christian Brabandt, Ken Takata, closes #2093)
1 parent c312b8b commit c3fdf7f

File tree

6 files changed

+162
-18
lines changed

6 files changed

+162
-18
lines changed

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ SRC_DOS = \
451451
src/xxd/Make_mvc.mak \
452452
nsis/gvim.nsi \
453453
nsis/gvim_version.nsh \
454+
nsis/vimrc.ini \
454455
nsis/README.txt \
455456
uninstal.txt \
456457
src/VisVim/Commands.cpp \

nsis/gvim.nsi

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ SilentInstall normal
8383
# These are the pages we use
8484
Page license
8585
Page components
86+
Page custom SetCustom ValidateCustom ": _vimrc setting"
8687
Page directory "" "" CheckInstallDir
8788
Page instfiles
8889
UninstPage uninstConfirm
@@ -135,6 +136,10 @@ Function .onInit
135136
StrCpy $1 "-register-OLE"
136137
StrCpy $2 "gvim evim gview gvimdiff vimtutor"
137138

139+
# Extract InstallOptions files
140+
# $PLUGINSDIR will automatically be removed when the installer closes
141+
InitPluginsDir
142+
File /oname=$PLUGINSDIR\vimrc.ini "vimrc.ini"
138143
FunctionEnd
139144

140145
Function .onUserAbort
@@ -404,7 +409,7 @@ Section "Add an Edit-with-Vim context menu entry"
404409
SectionEnd
405410

406411
##########################################################
407-
Section "Create a _vimrc if it doesn't exist"
412+
Section "Create a _vimrc if it doesn't exist" sec_vimrc_id
408413
SectionIn 1 3
409414

410415
StrCpy $1 "$1 -create-vimrc"
@@ -462,6 +467,45 @@ Section -post
462467
BringToFront
463468
SectionEnd
464469

470+
##########################################################
471+
Function SetCustom
472+
# Display the InstallOptions dialog
473+
474+
# Check if a _vimrc should be created
475+
SectionGetFlags ${sec_vimrc_id} $0
476+
IntOp $0 $0 & 1
477+
StrCmp $0 "1" +2 0
478+
Abort
479+
480+
Push $3
481+
InstallOptions::dialog "$PLUGINSDIR\vimrc.ini"
482+
Pop $3
483+
Pop $3
484+
FunctionEnd
485+
486+
Function ValidateCustom
487+
ReadINIStr $3 "$PLUGINSDIR\vimrc.ini" "Field 2" "State"
488+
StrCmp $3 "1" 0 +3
489+
StrCpy $1 "$1 -vimrc-remap no"
490+
Goto behave
491+
492+
StrCpy $1 "$1 -vimrc-remap win"
493+
494+
behave:
495+
ReadINIStr $3 "$PLUGINSDIR\vimrc.ini" "Field 5" "State"
496+
StrCmp $3 "1" 0 +3
497+
StrCpy $1 "$1 -vimrc-behave unix"
498+
Goto done
499+
500+
ReadINIStr $3 "$PLUGINSDIR\vimrc.ini" "Field 6" "State"
501+
StrCmp $3 "1" 0 +3
502+
StrCpy $1 "$1 -vimrc-behave mswin"
503+
Goto done
504+
505+
StrCpy $1 "$1 -vimrc-behave default"
506+
done:
507+
FunctionEnd
508+
465509
##########################################################
466510
Section Uninstall
467511
# Apparently $INSTDIR is set to the directory where the uninstaller is

nsis/vimrc.ini

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[Settings]
2+
NumFields=7
3+
4+
[Field 1]
5+
Type=GroupBox
6+
Left=0
7+
Right=-1
8+
Top=0
9+
Bottom=53
10+
Text=" Key remapping "
11+
12+
[Field 2]
13+
Type=radiobutton
14+
Text=Do not remap keys for Windows behavior (Default)
15+
Left=10
16+
Right=-10
17+
Top=17
18+
Bottom=25
19+
State=1
20+
Flags=GROUP
21+
22+
[Field 3]
23+
Type=radiobutton
24+
Text=Remap a few keys for Windows behavior (<C-V>, <C-C>, <C-A>, <C-S>, <C-F>, etc)
25+
Left=10
26+
Right=-10
27+
Top=30
28+
Bottom=47
29+
State=0
30+
Flags=NOTABSTOP
31+
32+
[Field 4]
33+
Type=GroupBox
34+
Left=0
35+
Right=-1
36+
Top=55
37+
Bottom=-5
38+
Text=" Mouse behavior "
39+
40+
[Field 5]
41+
Type=radiobutton
42+
Text=Right button extends selection, left button starts visual mode (Unix)
43+
Left=10
44+
Right=-5
45+
Top=72
46+
Bottom=80
47+
State=0
48+
Flags=GROUP
49+
50+
[Field 6]
51+
Type=radiobutton
52+
Text=Right button has a popup menu, left button starts select mode (Windows)
53+
Left=10
54+
Right=-5
55+
Top=85
56+
Bottom=93
57+
State=0
58+
Flags=NOTABSTOP
59+
60+
[Field 7]
61+
Type=radiobutton
62+
Text=Right button has a popup menu, left button starts visual mode (Default)
63+
Left=10
64+
Right=-5
65+
Top=98
66+
Bottom=106
67+
State=1
68+
Flags=NOTABSTOP

runtime/mswin.vim

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Set options and add mapping such that Vim behaves a lot like MS-Windows
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2017 Feb 09
4+
" Last change: 2017 Oct 28
55

66
" bail out if this isn't wanted (mrsvim.vim uses this).
77
if exists("g:skip_loading_mswin") && g:skip_loading_mswin
@@ -105,14 +105,15 @@ onoremap <C-F4> <C-C><C-W>c
105105
106106
if has("gui")
107107
" CTRL-F is the search dialog
108-
noremap <C-F> :promptfind<CR>
109-
inoremap <C-F> <C-\><C-O>:promptfind<CR>
110-
cnoremap <C-F> <C-\><C-C>:promptfind<CR>
111-
112-
" CTRL-H is the replace dialog
113-
noremap <C-H> :promptrepl<CR>
114-
inoremap <C-H> <C-\><C-O>:promptrepl<CR>
115-
cnoremap <C-H> <C-\><C-C>:promptrepl<CR>
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>"
116117
endif
117118

118119
" restore 'cpoptions'

src/dosinst.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,23 @@ char *(remap_choices[]) =
8080
"Do not remap keys for Windows behavior",
8181
"Remap a few keys for Windows behavior (CTRL-V, CTRL-C, CTRL-F, etc)",
8282
};
83-
int remap_choice = (int)remap_win;
83+
int remap_choice = (int)remap_no;
8484
char *remap_text = "- %s";
8585

8686
enum
8787
{
8888
mouse_xterm = 1,
89-
mouse_mswin
89+
mouse_mswin,,
90+
mouse_default
9091
};
9192
char *(mouse_choices[]) =
9293
{
9394
"\nChoose the way how Vim uses the mouse:",
9495
"right button extends selection (the Unix way)",
95-
"right button has a popup menu (the Windows way)",
96+
"right button has a popup menu, left button starts select mode (the Windows way)",
97+
"right button has a popup menu, left button starts visual mode",
9698
};
97-
int mouse_choice = (int)mouse_mswin;
99+
int mouse_choice = (int)mouse_default;
98100
char *mouse_text = "- The mouse %s";
99101

100102
enum
@@ -155,8 +157,7 @@ get_choice(char **table, int entries)
155157
{
156158
if (idx)
157159
printf("%2d ", idx);
158-
printf(table[idx]);
159-
printf("\n");
160+
puts(table[idx]);
160161
}
161162
printf("Choice: ");
162163
if (scanf("%d", &answer) != 1)
@@ -1176,6 +1177,8 @@ install_vimrc(int idx)
11761177
case mouse_mswin:
11771178
fprintf(fd, "behave mswin\n");
11781179
break;
1180+
case mouse_default:
1181+
break;
11791182
}
11801183
if ((tfd = fopen("diff.exe", "r")) != NULL)
11811184
{
@@ -2205,6 +2208,10 @@ print_cmd_line_help(void)
22052208
printf(" Create .bat files for Vim variants in the Windows directory.\n");
22062209
printf("-create-vimrc\n");
22072210
printf(" Create a default _vimrc file if one does not already exist.\n");
2211+
printf("-vimrc-remap [no|win]\n");
2212+
printf(" Remap keys when creating a default _vimrc file.\n");
2213+
printf("-vimrc-behave [unix|mswin|default]\n");
2214+
printf(" Set mouse behavior when creating a default _vimrc file.\n");
22082215
printf("-install-popup\n");
22092216
printf(" Install the Edit-with-Vim context menu entry\n");
22102217
printf("-install-openwith\n");
@@ -2260,6 +2267,28 @@ command_line_setup_choices(int argc, char **argv)
22602267
*/
22612268
init_vimrc_choices();
22622269
}
2270+
else if (strcmp(argv[i], "-vimrc-remap") == 0)
2271+
{
2272+
if (i + 1 == argc)
2273+
break;
2274+
i++;
2275+
if (strcmp(argv[i], "no") == 0)
2276+
remap_choice = remap_no;
2277+
else if (strcmp(argv[i], "win") == 0)
2278+
remap_choice = remap_win;
2279+
}
2280+
else if (strcmp(argv[i], "-vimrc-behave") == 0)
2281+
{
2282+
if (i + 1 == argc)
2283+
break;
2284+
i++;
2285+
if (strcmp(argv[i], "unix") == 0)
2286+
mouse_choice = mouse_xterm;
2287+
else if (strcmp(argv[i], "mswin") == 0)
2288+
mouse_choice = mouse_mswin;
2289+
else if (strcmp(argv[i], "default") == 0)
2290+
mouse_choice = mouse_default;
2291+
}
22632292
else if (strcmp(argv[i], "-install-popup") == 0)
22642293
{
22652294
init_popup_choice();
@@ -2424,8 +2453,7 @@ NULL
24242453
printf("\n");
24252454
for (i = 0; items[i] != NULL; ++i)
24262455
{
2427-
printf(items[i]);
2428-
printf("\n");
2456+
puts(items[i]);
24292457
printf("Hit Enter to continue, b (back) or q (quit help): ");
24302458
c = getchar();
24312459
rewind(stdin);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1232,
764766
/**/
765767
1231,
766768
/**/

0 commit comments

Comments
 (0)