From 2d2b5fa87e1cb62746f147f5eed8e19a2e5fc8d7 Mon Sep 17 00:00:00 2001 From: sql-koala Date: Wed, 21 Dec 2022 11:21:55 +0100 Subject: [PATCH 1/5] update readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index cc4a4c68c54..e0ae039fad3 100644 --- a/README.md +++ b/README.md @@ -592,6 +592,13 @@ 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"` +- the default mappings will not fit for users of custom keyboard layouts (workman, dvorak, etc.). + They need to disable them using `vim.disableDefaultPluginMappings` ### 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. From b733f293b9089b805330fae454a3bdfb93afa52e Mon Sep 17 00:00:00 2001 From: sql-koala Date: Wed, 21 Dec 2022 11:25:49 +0100 Subject: [PATCH 2/5] add option to disable default plugin mappings --- README.md | 5 ++-- package.json | 5 ++++ src/actions/plugins/pluginDefaultMappings.ts | 25 +++++++++++++++++--- src/configuration/configuration.ts | 2 ++ src/configuration/iconfiguration.ts | 4 ++++ test/testConfiguration.ts | 1 + 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0ae039fad3..ecdd9cea0c9 100644 --- a/README.md +++ b/README.md @@ -597,8 +597,9 @@ since 1.20, we internally use special key notation for surround ( ``, `< - custom mappings need to use these too.\ Example: `nnoremap s" iw"` -- the default mappings will not fit for users of custom keyboard layouts (workman, dvorak, etc.). - They need to disable them using `vim.disableDefaultPluginMappings` +- 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.disableDefaultPluginMappings` to true 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 3dd40cae53d..310f2e69bf3 100644 --- a/package.json +++ b/package.json @@ -760,6 +760,11 @@ "markdownDescription": "Enable the [Surround](https://github.com/tpope/vim-surround) plugin for Vim.", "default": true }, + "vim.disableDefaultPluginMappings": { + "type": "boolean", + "markdownDescription": "For users of custom keyboard layouts. Disable default keymappings starting with c/d/y. At present only affects surround.", + "default": false + }, "vim.argumentObjectSeparators": { "type": "array", "items": { diff --git a/src/actions/plugins/pluginDefaultMappings.ts b/src/actions/plugins/pluginDefaultMappings.ts index 600fc5cf852..59952288f30 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.disableDefaultPluginMappings + ? [] + : 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 1f106b42b5c..fa135e4bd91 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -246,6 +246,8 @@ class Configuration implements IConfiguration { surround = true; + disableDefaultPluginMappings = false; + argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; argumentObjectClosingDelimiters = [')', ']']; diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index faa8337cc11..e7071b86a71 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -191,6 +191,10 @@ export interface IConfiguration { */ surround: boolean; + /** + * Do not create default mappings for surround plugin + */ + disableDefaultPluginMappings: boolean; /** * Customize argument textobject delimiter and separator characters */ diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index f3bb165eab7..ad0221ececb 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -28,6 +28,7 @@ export class Configuration implements IConfiguration { sneakUseIgnorecaseAndSmartcase = false; sneakReplacesF = false; surround = false; + disableDefaultPluginMappings = false; argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; argumentObjectClosingDelimiters = [')', ']']; From 4e53958f1118108ef413657275eaf7aafc39d64d Mon Sep 17 00:00:00 2001 From: sql-koala Date: Wed, 21 Dec 2022 12:33:09 +0100 Subject: [PATCH 3/5] add test for csw --- test/plugins/surround.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/plugins/surround.test.ts b/test/plugins/surround.test.ts index 0a55a887ebf..77d29a2f8c0 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'], From 5ca514324be813291d04c2b0de0c6c01aa53eef6 Mon Sep 17 00:00:00 2001 From: sql-koala Date: Tue, 28 Mar 2023 00:31:38 +0200 Subject: [PATCH 4/5] switch to enable, default true --- README.md | 2 +- package.json | 4 ++-- src/actions/plugins/pluginDefaultMappings.ts | 8 ++++---- src/configuration/configuration.ts | 2 +- src/configuration/iconfiguration.ts | 4 ++-- test/testConfiguration.ts | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ecdd9cea0c9..8f3b6a0e497 100644 --- a/README.md +++ b/README.md @@ -598,7 +598,7 @@ since 1.20, we internally use special key notation for surround ( ``, `< - 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.disableDefaultPluginMappings` to true and then create a mapping for the 3 key sequences above, like so:\ + 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 diff --git a/package.json b/package.json index 310f2e69bf3..d9f032fe130 100644 --- a/package.json +++ b/package.json @@ -760,10 +760,10 @@ "markdownDescription": "Enable the [Surround](https://github.com/tpope/vim-surround) plugin for Vim.", "default": true }, - "vim.disableDefaultPluginMappings": { + "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": false + "default": true }, "vim.argumentObjectSeparators": { "type": "array", diff --git a/src/actions/plugins/pluginDefaultMappings.ts b/src/actions/plugins/pluginDefaultMappings.ts index 59952288f30..026afc32135 100644 --- a/src/actions/plugins/pluginDefaultMappings.ts +++ b/src/actions/plugins/pluginDefaultMappings.ts @@ -48,10 +48,10 @@ export class PluginDefaultMappings { ]; public static getPluginDefaultMappings(mode: string, config: IConfiguration): IKeyRemapping[] { - return config.disableDefaultPluginMappings - ? [] - : this.defaultMappings + return config.enableDefaultPluginMappings + ? this.defaultMappings .filter((m) => m.mode === mode && config[m.configSwitch]) - .map((m) => m.mapping); + .map((m) => m.mapping) + : []; } } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index fa135e4bd91..f56f040b893 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -246,7 +246,7 @@ class Configuration implements IConfiguration { surround = true; - disableDefaultPluginMappings = false; + enableDefaultPluginMappings = true; argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index e7071b86a71..65d2858f2ae 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -192,9 +192,9 @@ export interface IConfiguration { surround: boolean; /** - * Do not create default mappings for surround plugin + * create default mappings for surround plugin */ - disableDefaultPluginMappings: boolean; + enableDefaultPluginMappings: boolean; /** * Customize argument textobject delimiter and separator characters */ diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index ad0221ececb..1bca8f56c05 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -28,7 +28,7 @@ export class Configuration implements IConfiguration { sneakUseIgnorecaseAndSmartcase = false; sneakReplacesF = false; surround = false; - disableDefaultPluginMappings = false; + enableDefaultPluginMappings = true; argumentObjectSeparators = [',']; argumentObjectOpeningDelimiters = ['(', '[']; argumentObjectClosingDelimiters = [')', ']']; From e64aca92fa520798ce764b493759db83a79c2304 Mon Sep 17 00:00:00 2001 From: Jason Fields Date: Tue, 10 Sep 2024 22:09:13 -0400 Subject: [PATCH 5/5] prettier Co-authored-by: Quaid Bartolomei <59486980+QuaidBartolomei@users.noreply.github.com> --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0867b5f4d37..a7692530ba8 100644 --- a/README.md +++ b/README.md @@ -609,6 +609,7 @@ since 1.20, we internally use special key notation for surround ( ``, `< 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. Usage examples: