Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
#30 support ^
Browse files Browse the repository at this point in the history
  • Loading branch information
74th committed Apr 15, 2016
1 parent eb3ba6e commit dbadcf4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

vim emulator for VSCode

![vimanimetion](https://raw.githubusercontent.com/74th/vscode-vim/master/tutorial/tutorial1.gif)
Expand Down Expand Up @@ -41,11 +42,11 @@ npm run-script build

## support

* h j k l 0 $ w W b B e E tx fx Tx Fx gg G
* h j k l 0 $ ^ w W b B e E tx fx Tx Fx gg G
* Nh Nj Nk Nl Nw NW Nb NB Ne NE Ntx Nfx NTx NFx NG
* i a s o x I A S O X
* Nx
* d y c dd yy cc D C p P
* d y c dd yy cc D C p P d$ y$ c$ ...
* Ndd Nyy Ncc
* v V
* .
Expand Down Expand Up @@ -100,6 +101,13 @@ MIT License

## update

### 0.3.3

* support ^
* change icon

![icon](https://raw.githubusercontent.com/74th/vscode-vim/master/vim.png)

### 0.3.2

* update for vscode 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type": "git",
"url": "https://github.com/74th/vscode-vim.git"
},
"version": "0.3.2",
"version": "0.3.3",
"publisher": "74th",
"engines": {
"vscode": "^1.0.0"
Expand Down
33 changes: 27 additions & 6 deletions src/core/CommandFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {HomeMotion} from "../motion/HomeMotion";
import {EndMotion} from "../motion/EndMotion";
import {FindCharacterMotion} from "../motion/FindCharacterMotion";
import {WordMotion} from "../motion/WordMotion";
import {LineHeadMotion} from "../motion/LineHeadMotion";
import {LineHeadMotion, LineHeadTarget} from "../motion/LineHeadMotion";

export class CommandFactory implements ICommandFactory {

Expand Down Expand Up @@ -187,6 +187,9 @@ export class CommandFactory implements ICommandFactory {
case CommandName.moveEndAction:
this.moveEndAction();
return;
case CommandName.moveFirstNonBlankCharAction:
this.moveFirstNonBlankCharAction();
return;
case CommandName.moveFindCharacterAction:
this.moveFindCharacterAction(command.isReverse);
return;
Expand Down Expand Up @@ -234,6 +237,9 @@ export class CommandFactory implements ICommandFactory {
case CommandName.endMotion:
this.endMotion();
return;
case CommandName.firstNonBlankCharMotion:
this.firstNonBlankCharMotion();
return;
case CommandName.findCharacterMotion:
this.findCharacterMotion(command.isReverse);
return;
Expand Down Expand Up @@ -349,7 +355,7 @@ export class CommandFactory implements ICommandFactory {
// I
private insertHomeAction() {
let m = new LineHeadMotion();
m.SetCurrentLineOption();
m.TargetLine = LineHeadTarget.Current;
this.action = new ApplyInsertModeAction(m);
}

Expand Down Expand Up @@ -466,6 +472,13 @@ export class CommandFactory implements ICommandFactory {
this.action = this.createMoveAction(new EndMotion());
}

// ^
private moveFirstNonBlankCharAction() {
let m = new LineHeadMotion();
m.TargetLine = LineHeadTarget.Current;
this.action = this.createMoveAction(m);
}

// fx Fx
private moveFindCharacterAction(isReverse) {
let a = new MoveAction();
Expand Down Expand Up @@ -510,7 +523,7 @@ export class CommandFactory implements ICommandFactory {
private moveLastLineAction() {
let a = new MoveAction();
let m = new LineHeadMotion();
m.SetLastLineOption();
m.TargetLine = LineHeadTarget.Last;
a.SetMotion(m);
this.action = a;
}
Expand All @@ -519,7 +532,7 @@ export class CommandFactory implements ICommandFactory {
private moveFirstLineAction() {
let a = new MoveAction();
let m = new LineHeadMotion();
m.SetFirstLineOption();
m.TargetLine = LineHeadTarget.First;
a.SetMotion(m);
this.action = a;
}
Expand Down Expand Up @@ -575,6 +588,14 @@ export class CommandFactory implements ICommandFactory {
let a = <IRequireMotionAction>this.action;
a.SetMotion(new EndMotion());
}

// c^
private firstNonBlankCharMotion() {
let a = <IRequireMotionAction>this.action;
let m = new LineHeadMotion();
m.TargetLine = LineHeadTarget.Current;
a.SetMotion(m);
}

// fx Fx
private findCharacterMotion(isReverse) {
Expand Down Expand Up @@ -619,7 +640,7 @@ export class CommandFactory implements ICommandFactory {
// cG
private lastLineMotion() {
let m = new LineHeadMotion();
m.SetLastLineOption();
m.TargetLine = LineHeadTarget.Last;
let a = <IRequireMotionAction>this.action;
a.SetMotion(m);
a.SetLineOption();
Expand All @@ -628,7 +649,7 @@ export class CommandFactory implements ICommandFactory {
// cgg
private firstLineMotion() {
let m = new LineHeadMotion();
m.SetFirstLineOption();
m.TargetLine = LineHeadTarget.First;
let a = <IRequireMotionAction>this.action;
a.SetMotion(m);
a.SetLineOption();
Expand Down
6 changes: 6 additions & 0 deletions src/core/KeyBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ const DefaultKeyBindings: IKeyBindings = {
"$": {
cmd: CommandName.moveEndAction
},
"^": {
cmd: CommandName.moveFirstNonBlankCharAction
},
".": {
cmd: CommandName.repeat
}
Expand Down Expand Up @@ -512,6 +515,9 @@ const DefaultKeyBindings: IKeyBindings = {
},
"$": {
cmd: CommandName.endMotion
},
"^": {
cmd: CommandName.firstNonBlankCharMotion
}
},

Expand Down
29 changes: 10 additions & 19 deletions src/motion/LineHeadMotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {AbstractMotion} from "./AbstractMotion";
import * as Utils from "../Utils";
import {Position} from "../VimStyle";

enum Target {
export enum LineHeadTarget {
Current,
First,
Last,
Expand All @@ -11,42 +11,33 @@ enum Target {

export class LineHeadMotion extends AbstractMotion {

private targetLine: Target;
public TargetLine: LineHeadTarget;
public IsSkipSpaces: boolean;

constructor() {
super();
this.targetLine = Target.Number;
}

public SetFirstLineOption() {
this.targetLine = Target.First;
}

public SetLastLineOption() {
this.targetLine = Target.Last;
}
public SetCurrentLineOption() {
this.targetLine = Target.Current;
this.TargetLine = LineHeadTarget.Number;
this.IsSkipSpaces = false;
}

public CalculateEnd(editor: IEditor, start: IPosition): IPosition {

let lineDocument: string;
let lineNumber: number;
switch (this.targetLine) {
case Target.Current:
switch (this.TargetLine) {
case LineHeadTarget.Current:
lineDocument = editor.ReadLineAtCurrentPosition();
lineNumber = start.Line;
break;
case Target.First:
case LineHeadTarget.First:
lineNumber = 0;
lineDocument = editor.ReadLine(lineNumber);
break;
case Target.Last:
case LineHeadTarget.Last:
lineNumber = editor.GetLastLineNum();
lineDocument = editor.ReadLine(lineNumber);
break;
case Target.Number:
case LineHeadTarget.Number:
lineNumber = this.GetCount();
let lastLineNum = editor.GetLastLineNum();
if (lineNumber > lastLineNum) {
Expand Down
2 changes: 2 additions & 0 deletions typings/vscode-vim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ declare const enum CommandName {
moveWORDEndAction,
moveHomeAction,
moveEndAction,
moveFirstNonBlankCharAction,
moveFindCharacterAction,
moveTillCharacterAction,
moveGotoLineAction,
Expand All @@ -342,6 +343,7 @@ declare const enum CommandName {
WORDEndMotion,
homeMotion,
endMotion,
firstNonBlankCharMotion,
findCharacterMotion,
tillCharacterMotion,
gotoLineMotion,
Expand Down

1 comment on commit dbadcf4

@wayt
Copy link

@wayt wayt commented on dbadcf4 Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be possible to bind it also on == in normal mode (like vim).
I know == should also indent the line, but it's a first step :)

Please sign in to comment.