Skip to content

Commit

Permalink
Make ReplaceWithRegister work in visual mode
Browse files Browse the repository at this point in the history
Fixes #4015
  • Loading branch information
stevenguh committed Aug 29, 2019
1 parent c425da3 commit 56982c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,9 @@ Once active, type `gr` (say "go replace") followed by a motion to describe the t

| Motion Command | Description |
| -------------- | ---------------------------------------------------------------------------------- |
| `gr<motion>` | Replace the text described by the motion with the contents of the default register |
| `"agr<motion>` | 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 |
| `<count>grr` | Replace the specified number of lines with the contents of the default register |
| `[count]["a]gr<motion>`| Replace the text described by the motion with the contents of the default register or the specified register `a` in the example |
| `[count]["a]grr` | Replace the \[count\] lines or current line with the contents of the default register or the specified register `a` in the example |
| `{Visual}["a]gr` | Replace the selection with the contents of default register or the specified register `a` in the example |

## 🎩 VSCodeVim tricks!

Expand Down
4 changes: 2 additions & 2 deletions src/actions/plugins/replaceWithRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/plugins/replaceWithRegister.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
});

0 comments on commit 56982c2

Please sign in to comment.