Special keys in Insert Mode

This commit is contained in:
rebornix 2016-08-16 07:55:48 -07:00
parent 7b24b7c873
commit d44497cbac
3 changed files with 118 additions and 5 deletions

View File

@ -246,15 +246,15 @@ Status | Command | Description
---|--------|------------------------------
| CTRL-V {char}.. | insert character literally, or enter decimal byte value
:warning: | NL or CR or CTRL-M or CTRL-J | begin new line
| CTRL-E | insert the character from below the cursor
| CTRL-Y | insert the character from above the cursor
:white_check_mark: | CTRL-E | insert the character from below the cursor
:white_check_mark: | CTRL-Y | insert the character from above the cursor
| CTRL-A | insert previously inserted text
| CTRL-@ | insert previously inserted text and stop Insert mode
| CTRL-R {0-9a-z%#:.-="} | insert the contents of a register
:white_check_mark: | CTRL-R {0-9a-z%#:.-="} | insert the contents of a register
| CTRL-N | insert next match of identifier before the cursor
| CTRL-P | insert previous match of identifier before the cursor
| CTRL-X ... | complete the word before the cursor in various ways
| BS or CTRL-H | delete the character before the cursor
:white_check_mark: | BS or CTRL-H | delete the character before the cursor
:white_check_mark: | Del | delete the character under the cursor
:white_check_mark: | CTRL-W | delete word before the cursor
| CTRL-U | delete all entered characters in the current line

View File

@ -77,6 +77,11 @@
"command": "extension.vim_ctrl+b",
"when": "editorTextFocus && vim.mode != 'Insert Mode'"
},
{
"key": "ctrl+h",
"command": "extension.vim_ctrl+h",
"when": "editorTextFocus && vim.mode == 'Insert Mode'"
},
{
"key": "ctrl+e",
"command": "extension.vim_ctrl+e",

View File

@ -409,6 +409,49 @@ class CommandRegister extends BaseCommand {
}
}
@RegisterAction
class CommandInsertRegisterContent extends BaseCommand {
modes = [ModeName.Insert];
keys = ["ctrl+r", "<character>"];
isCompleteAction = false;
public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.recordedState.registerName = this.keysPressed[1];
const register = await Register.get(vimState);
let text: string;
if (typeof register.text === "object") {
text = (register.text as string []).join("\n");
} else {
text = register.text;
}
if (register.registerMode === RegisterMode.LineWise) {
text += "\n";
}
await TextEditor.insertAt(text, position);
vimState.currentMode = ModeName.Insert;
vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
return vimState;
}
public doesActionApply(vimState: VimState, keysPressed: string[]): boolean {
const register = keysPressed[1];
return super.doesActionApply(vimState, keysPressed) && Register.isValidRegister(register);
}
public couldActionApply(vimState: VimState, keysPressed: string[]): boolean {
const register = keysPressed[1];
return super.couldActionApply(vimState, keysPressed) && Register.isValidRegister(register);
}
}
@RegisterAction
class CommandEsc extends BaseCommand {
modes = [
@ -472,6 +515,32 @@ class CommandCtrlE extends BaseCommand {
}
}
@RegisterAction
class CommandInsertBelowChar extends BaseCommand {
modes = [ModeName.Insert];
keys = ["ctrl+e"];
public async exec(position: Position, vimState: VimState): Promise<VimState> {
if (TextEditor.isLastLine(position)) {
return vimState;
}
const charBelowCursorPosition = position.getDownByCount(1);
if (charBelowCursorPosition.isLineEnd()) {
return vimState;
}
const char = TextEditor.getText(new vscode.Range(charBelowCursorPosition, charBelowCursorPosition.getRight()));
await TextEditor.insert(char, position);
vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
return vimState;
}
}
@RegisterAction
class CommandCtrlY extends BaseCommand {
modes = [ModeName.Normal];
@ -484,6 +553,32 @@ class CommandCtrlY extends BaseCommand {
}
}
@RegisterAction
class CommandInsertAboveChar extends BaseCommand {
modes = [ModeName.Insert];
keys = ["ctrl+y"];
public async exec(position: Position, vimState: VimState): Promise<VimState> {
if (TextEditor.isFirstLine(position)) {
return vimState;
}
const charAboveCursorPosition = position.getUpByCount(1);
if (charAboveCursorPosition.isLineEnd()) {
return vimState;
}
const char = TextEditor.getText(new vscode.Range(charAboveCursorPosition, charAboveCursorPosition.getRight()));
await TextEditor.insert(char, position);
vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
return vimState;
}
}
@RegisterAction
class CommandCtrlC extends CommandEsc {
keys = ["<C-c>"];
@ -743,7 +838,7 @@ class CommandInsertInInsertMode extends BaseCommand {
// The hard case is . where we have to track cursor pos since we don't
// update the view
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const char = this.keysPressed[this.keysPressed.length - 1];
const char = this.keysPressed[this.keysPressed.length - 1];
if (char === "<BS>") {
const newPosition = await TextEditor.backspace(position);
@ -766,6 +861,19 @@ class CommandInsertInInsertMode extends BaseCommand {
}
}
@RegisterAction
class CommandCtrlHInInsertMode extends BaseCommand {
modes = [ModeName.Insert];
keys = ["ctrl+h"];
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const newPosition = await TextEditor.backspace(position);
vimState.cursorPosition = newPosition;
vimState.cursorStartPosition = newPosition;
return vimState;
}
}
@RegisterAction
export class CommandSearchForwards extends BaseCommand {
modes = [ModeName.Normal];