Skip to content

Commit 36d8e41

Browse files
sql-koalaactions-user
authored andcommitted
surround fixup: switch for default mappings, update doc.
1 parent a967a85 commit 36d8e41

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ Some examples:
511511
- `"test"` with cursor inside quotes type `ds"` to end up with `test`
512512
- `"test"` with cursor inside quotes type `cs"t` and enter `123>` to end up with `<123>test</123>`
513513

514+
Surround mappings:
515+
since 1.20, we internally use special key notation for surround ( `<plugys>`, `<plugcs>`, `<plugds>` ), for which we create default mappings. This has two consequences:
516+
517+
- custom mappings need to use these too.\
518+
Example: `nnoremap s" <plugys>iw"`
519+
- the default mappings will not fit for users of custom keyboard layouts (workman, etc.).
520+
They need to disable them using `vim.disableDefaultPluginMappings`
521+
514522
### vim-commentary
515523

516524
Similar to [vim-commentary](https://github.com/tpope/vim-commentary), but uses the VS Code native _Toggle Line Comment_ and _Toggle Block Comment_ features.

src/actions/plugins/pluginDefaultMappings.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,30 @@ export class PluginDefaultMappings {
2828
configSwitch: 'surround',
2929
mapping: { before: ['d', 's'], after: ['<plugds>'] },
3030
},
31+
// support some special cases with mappings
32+
// see: https://github.com/tpope/vim-surround/blob/master/doc/surround.txt, TARGETS w,W,s
33+
{
34+
mode: 'normalModeKeyBindingsNonRecursive',
35+
configSwitch: 'surround',
36+
mapping: { before: ['c', 's', 'w'], after: ['<plugys>', 'i', 'w'] },
37+
},
38+
{
39+
mode: 'normalModeKeyBindingsNonRecursive',
40+
configSwitch: 'surround',
41+
mapping: { before: ['c', 's', 'W'], after: ['<plugys>', 'i', 'W'] },
42+
},
43+
{
44+
mode: 'normalModeKeyBindingsNonRecursive',
45+
configSwitch: 'surround',
46+
mapping: { before: ['c', 's', 's'], after: ['<plugys>', 'i', 's'] },
47+
},
3148
];
3249

3350
public static getPluginDefaultMappings(mode: string, config: IConfiguration): IKeyRemapping[] {
34-
return this.defaultMappings
35-
.filter((m) => m.mode === mode && config[m.configSwitch])
36-
.map((m) => m.mapping);
51+
return config.disableDefaultPluginMappings
52+
? []
53+
: this.defaultMappings
54+
.filter((m) => m.mode === mode && config[m.configSwitch])
55+
.map((m) => m.mapping);
3756
}
3857
}

src/configuration/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class Configuration implements IConfiguration {
240240

241241
surround = true;
242242

243+
disableDefaultPluginMappings = false;
244+
243245
argumentObjectSeparators = [','];
244246
argumentObjectOpeningDelimiters = ['(', '['];
245247
argumentObjectClosingDelimiters = [')', ']'];

src/configuration/iconfiguration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ export interface IConfiguration {
166166
*/
167167
surround: boolean;
168168

169+
/**
170+
* Do not create default mappings for surround plugin
171+
*/
172+
disableDefaultPluginMappings: boolean;
173+
169174
/**
170175
* Customize argument textobject delimiter and separator characters
171176
*/

test/testConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class Configuration implements IConfiguration {
2727
sneakUseIgnorecaseAndSmartcase = false;
2828
sneakReplacesF = false;
2929
surround = false;
30+
disableDefaultPluginMappings = false;
3031
argumentObjectSeparators = [','];
3132
argumentObjectOpeningDelimiters = ['(', '['];
3233
argumentObjectClosingDelimiters = [')', ']'];

0 commit comments

Comments
 (0)