Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adjust the way surround loads its default keybindings #9403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,15 @@ Some examples:
- `"test"` with cursor inside quotes type `ds"` to end up with `test`
- `"test"` with cursor inside quotes type `cs"t` and enter `123>` to end up with `<123>test</123>`

Surround mappings:
since 1.20, we internally use special key notation for surround ( `<plugys>`, `<plugcs>`, `<plugds>` ), for which we create default mappings. This has two consequences:

- custom mappings need to use these too.\
Example: `nnoremap s" <plugys>iw"`
- if you use a custom keyboard layout (workman, dvorak, etc.), the default mappings will not fit for you.
You need to disable by settting `vim.enableDefaultPluginMappings` to false and then create a mapping for the 3 key sequences above, like so:\
Example: `nnoremap ys <plugys>` where you replace `ys` with what fits for your layout.

### vim-commentary

Similar to [vim-commentary](https://github.com/tpope/vim-commentary), but uses the VS Code native _Toggle Line Comment_ and _Toggle Block Comment_ features.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@
"markdownDescription": "Enable the [Surround](https://github.com/tpope/vim-surround) plugin for Vim.",
"default": true
},
"vim.enableDefaultPluginMappings": {
"type": "boolean",
"markdownDescription": "For users of custom keyboard layouts. Disable default keymappings starting with c/d/y. At present only affects surround.",
"default": true
},
"vim.argumentObjectSeparators": {
"type": "array",
"items": {
Expand Down
25 changes: 22 additions & 3 deletions src/actions/plugins/pluginDefaultMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,30 @@ export class PluginDefaultMappings {
configSwitch: 'surround',
mapping: { before: ['d', 's'], after: ['<plugds>'] },
},
// support some special cases with mappings
// see: https://github.com/tpope/vim-surround/blob/master/doc/surround.txt, TARGETS w,W,s
{
mode: 'normalModeKeyBindingsNonRecursive',
configSwitch: 'surround',
mapping: { before: ['c', 's', 'w'], after: ['<plugys>', 'i', 'w'] },
},
{
mode: 'normalModeKeyBindingsNonRecursive',
configSwitch: 'surround',
mapping: { before: ['c', 's', 'W'], after: ['<plugys>', 'i', 'W'] },
},
{
mode: 'normalModeKeyBindingsNonRecursive',
configSwitch: 'surround',
mapping: { before: ['c', 's', 's'], after: ['<plugys>', 'i', 's'] },
},
];

public static getPluginDefaultMappings(mode: string, config: IConfiguration): IKeyRemapping[] {
return this.defaultMappings
.filter((m) => m.mode === mode && config[m.configSwitch])
.map((m) => m.mapping);
return config.enableDefaultPluginMappings
? this.defaultMappings
.filter((m) => m.mode === mode && config[m.configSwitch])
.map((m) => m.mapping)
: [];
}
}
2 changes: 2 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ class Configuration implements IConfiguration {

surround = true;

enableDefaultPluginMappings = true;

argumentObjectSeparators = [','];
argumentObjectOpeningDelimiters = ['(', '['];
argumentObjectClosingDelimiters = [')', ']'];
Expand Down
4 changes: 4 additions & 0 deletions src/configuration/iconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export interface IConfiguration {
*/
surround: boolean;

/**
* create default mappings for surround plugin
*/
enableDefaultPluginMappings: boolean;
/**
* Customize argument textobject delimiter and separator characters
*/
Expand Down
7 changes: 7 additions & 0 deletions test/plugins/surround.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ suite('surround plugin', () => {
end: ['first |( line ) test'],
});

newTest({
title: "'csw' as shortform for ysiw",
start: ['first li|ne test'],
keysPressed: 'csw(',
end: ['first |( line ) test'],
});

newTest({
title: "'ysw)' surrounds word without space",
start: ['first |line test'],
Expand Down
1 change: 1 addition & 0 deletions test/testConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Configuration implements IConfiguration {
sneakUseIgnorecaseAndSmartcase = false;
sneakReplacesF = false;
surround = false;
enableDefaultPluginMappings = true;
argumentObjectSeparators = [','];
argumentObjectOpeningDelimiters = ['(', '['];
argumentObjectClosingDelimiters = [')', ']'];
Expand Down