Skip to content

Commit

Permalink
Support for vi 'o' (add new line) command, fixes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 3, 2017
1 parent a22adf2 commit ab0fcdb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
17 changes: 17 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,19 @@ protected boolean viYankTo(int startPos, int endPos) {
return true;
}

protected boolean viOpenLineAbove() {
while (buf.move(-1) == -1 && buf.prevChar() != '\n') ;
buf.write('\n');
buf.move(-1);
return setKeyMap(VIINS);
}

protected boolean viOpenLineBelow() {
while (buf.move(1) == 1 && buf.currChar() != '\n') ;
buf.write('\n');
return setKeyMap(VIINS);
}

/**
* Pasts the yank buffer to the right of the current cursor position
* and moves the cursor to the end of the pasted region.
Expand Down Expand Up @@ -3173,6 +3186,8 @@ protected Map<String, Widget> builtinWidgets() {
widgets.put(VI_INSERT_COMMENT, this::viInsertComment);
widgets.put(VI_KILL_LINE, this::viKillWholeLine);
widgets.put(VI_MATCH_BRACKET, this::viMatchBracket);
widgets.put(VI_OPEN_LINE_ABOVE, this::viOpenLineAbove);
widgets.put(VI_OPEN_LINE_BELOW, this::viOpenLineBelow);
widgets.put(VI_PUT_AFTER, this::viPutAfter);
widgets.put(VI_REPEAT_FIND, this::viRepeatFind);
widgets.put(VI_REPEAT_SEARCH, this::viRepeatSearch);
Expand Down Expand Up @@ -5011,6 +5026,7 @@ public KeyMap<Binding> viCmd() {
bind(vicmd, VI_FETCH_HISTORY, "G");
bind(vicmd, VI_INSERT_BOL, "I");
bind(vicmd, VI_REV_REPEAT_SEARCH, "N");
bind(vicmd, VI_OPEN_LINE_ABOVE, "O");
bind(vicmd, VI_PUT_AFTER, "P");
bind(vicmd, VI_REPLACE, "R");
bind(vicmd, VI_KILL_LINE, "S");
Expand All @@ -5036,6 +5052,7 @@ public KeyMap<Binding> viCmd() {
bind(vicmd, UP_LINE_OR_HISTORY, "k");
bind(vicmd, VI_FORWARD_CHAR, "l");
bind(vicmd, VI_REPEAT_SEARCH, "n");
bind(vicmd, VI_OPEN_LINE_BELOW, "o");
bind(vicmd, VI_PUT_AFTER, "p");
bind(vicmd, VI_REPLACE_CHARS, "r");
bind(vicmd, VI_SUBSTITUTE, "s");
Expand Down
24 changes: 23 additions & 1 deletion reader/src/test/java/org/jline/reader/impl/ViMoveModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,29 @@ public void testS() throws Exception {
.enter();
assertLine("dogfishhead", b, false);
}


@Test
public void testO() throws Exception {
// O insert a line
TestBuffer b = (new TestBuffer("great lakes brewery"))
.escape()
.left(6)
.append("Odog ")
.enter();
assertLine("dog \ngreat lakes brewery", b, false);
}

@Test
public void testo() throws Exception {
// O insert a line
TestBuffer b = (new TestBuffer("great lakes brewery"))
.escape()
.left(6)
.append("odog ")
.enter();
assertLine("great lakes brewery\ndog ", b, false);
}

@Test
public void testEndOfLine() throws Exception {
/*
Expand Down

0 comments on commit ab0fcdb

Please sign in to comment.