diff --git a/README.md b/README.md index 7832a5825a7..754484d50a6 100644 --- a/README.md +++ b/README.md @@ -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` +Surround mappings: +since 1.20, we internally use special key notation for surround ( ``, ``, `` ), for which we create default mappings. This has two consequences: + +- custom mappings need to use these too.\ + Example: `nnoremap s" 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 ` 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. diff --git a/package.json b/package.json index 6c863056994..97dc62bec15 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/actions/plugins/pluginDefaultMappings.ts b/src/actions/plugins/pluginDefaultMappings.ts index 600fc5cf852..026afc32135 100644 --- a/src/actions/plugins/pluginDefaultMappings.ts +++ b/src/actions/plugins/pluginDefaultMappings.ts @@ -28,11 +28,30 @@ export class PluginDefaultMappings { configSwitch: 'surround', mapping: { before: ['d', 's'], after: [''] }, }, + // 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: ['', 'i', 'w'] }, + }, + { + mode: 'normalModeKeyBindingsNonRecursive', + configSwitch: 'surround', + mapping: { before: ['c', 's', 'W'], after: ['', 'i', 'W'] }, + }, + { + mode: 'normalModeKeyBindingsNonRecursive', + configSwitch: 'surround', + mapping: { before: ['c', 's', 's'], after: ['', '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) + : []; } } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 0f0f53ac158..5a432550dbd 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -262,6 +262,8 @@ class Configuration implements IConfiguration { surround = true; + enableDefaultPluginMappings = true; + argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; argumentObjectClosingDelimiters = [')', ']']; diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index f84e9bfc628..1fcde4189cf 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -175,6 +175,10 @@ export interface IConfiguration { */ surround: boolean; + /** + * create default mappings for surround plugin + */ + enableDefaultPluginMappings: boolean; /** * Customize argument textobject delimiter and separator characters */ diff --git a/test/plugins/surround.test.ts b/test/plugins/surround.test.ts index 2cc4bc60a39..0b0d089bcda 100644 --- a/test/plugins/surround.test.ts +++ b/test/plugins/surround.test.ts @@ -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'], diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index 614976d110e..85fd31cd9b4 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -29,6 +29,7 @@ export class Configuration implements IConfiguration { sneakUseIgnorecaseAndSmartcase = false; sneakReplacesF = false; surround = false; + enableDefaultPluginMappings = true; argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; argumentObjectClosingDelimiters = [')', ']'];