diff --git a/README.md b/README.md index b6bd20f1dbb..39585e5f3f8 100644 --- a/README.md +++ b/README.md @@ -598,12 +598,11 @@ Based on [ReplaceWithRegister](https://github.com/vim-scripts/ReplaceWithRegiste Once active, type `gr` (say "go replace") followed by a motion to describe the text you want replaced by the contents of the register. -| Motion Command | Description | -| -------------- | ---------------------------------------------------------------------------------- | -| `gr` | Replace the text described by the motion with the contents of the default register | -| `"agr` | Replace the text described by the motion with the contents of the `a` register | -| `grr` | Replace the currentline with the contents of the default register | -| `grr` | Replace the specified number of lines with the contents of the default register | +| Motion Command | Description | +| ----------------------- | --------------------------------------------------------------------------------------- | +| `[count]["a]gr` | Replace the text described by the motion with the contents of the specified register | +| `[count]["a]grr` | Replace the \[count\] lines or current line with the contents of the specified register | +| `{Visual}["a]gr` | Replace the selection with the contents of the specified register | ## 🎩 VSCodeVim tricks! diff --git a/src/actions/plugins/replaceWithRegister.ts b/src/actions/plugins/replaceWithRegister.ts index 904d06ff5dd..61f8d5e0404 100644 --- a/src/actions/plugins/replaceWithRegister.ts +++ b/src/actions/plugins/replaceWithRegister.ts @@ -11,7 +11,7 @@ import { RegisterAction } from './../base'; @RegisterAction export class ReplaceOperator extends BaseOperator { public keys = ['g', 'r']; - public modes = [ModeName.Normal]; + public modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; public doesActionApply(vimState: VimState, keysPressed: string[]): boolean { return configuration.replaceWithRegister && super.doesActionApply(vimState, keysPressed); @@ -27,7 +27,7 @@ export class ReplaceOperator extends BaseOperator { const replaceWith = register.text as string; await TextEditor.replace(range, replaceWith); - + await vimState.setCurrentMode(ModeName.Normal); return updateCursorPosition(vimState, range, replaceWith); } } diff --git a/src/cmd_line/commands/sort.ts b/src/cmd_line/commands/sort.ts index bdb1f3ac5a1..b6fa786f9be 100644 --- a/src/cmd_line/commands/sort.ts +++ b/src/cmd_line/commands/sort.ts @@ -58,9 +58,9 @@ export class SortCommand extends node.CommandBase { let lastLineLength = originalLines[originalLines.length - 1].length; - const compareFn = this._arguments.ignoreCase ? - (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()) : - (a: string, b: string) => a.localeCompare(b); + const compareFn = this._arguments.ignoreCase + ? (a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase()) + : (a: string, b: string) => a.localeCompare(b); let sortedLines = originalLines.sort(compareFn); diff --git a/src/configuration/notation.ts b/src/configuration/notation.ts index 7e7d8a6634b..a2f2e81e246 100644 --- a/src/configuration/notation.ts +++ b/src/configuration/notation.ts @@ -17,7 +17,7 @@ export class Notation { // Converts keystroke like to a single control character like \t public static ToControlCharacter(key: string) { - if (key === "") { + if (key === '') { return '\t'; } diff --git a/test/plugins/replaceWithRegister.test.ts b/test/plugins/replaceWithRegister.test.ts index 9be1453fb8c..7cc74fcc145 100644 --- a/test/plugins/replaceWithRegister.test.ts +++ b/test/plugins/replaceWithRegister.test.ts @@ -112,4 +112,25 @@ suite('replaceWithRegister plugin', () => { keysPressed: `${YankInnerWord}2grr`, end: ['|first', 'third'], }); + + newTest({ + title: 'Replaces in visual mode', + start: ['|first second'], + keysPressed: `${YankInnerWord}wviw${ReplaceOperator}`, + end: ['first firs|t'], + }); + + newTest({ + title: 'Replaces in visual mode using a specified register', + start: ['|first second'], + keysPressed: `"a${YankInnerWord}wviw"a${ReplaceOperator}`, + end: ['first firs|t'], + }); + + newTest({ + title: 'Replaces in visual line mode', + start: ['|first second'], + keysPressed: `${YankInnerWord}wV${ReplaceOperator}`, + end: ['firs|t'], + }); });