Skip to content

Commit

Permalink
Support for the vi 'J' (join lines) command, #81
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 3, 2017
1 parent ab0fcdb commit cddb9ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 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 @@ -2708,6 +2708,17 @@ protected boolean quotedInsert() {
return true;
}

protected boolean viJoin() {
if (buf.down()) {
while (buf.move(-1) == -1 && buf.prevChar() != '\n') ;
buf.backspace();
buf.write(' ');
buf.move(-1);
return true;
}
return false;
}

protected boolean viKillWholeLine() {
return killWholeLine() && setKeyMap(VIINS);
}
Expand Down Expand Up @@ -3184,6 +3195,7 @@ protected Map<String, Widget> builtinWidgets() {
widgets.put(VI_INSERT, this::viInsert);
widgets.put(VI_INSERT_BOL, this::viInsertBol);
widgets.put(VI_INSERT_COMMENT, this::viInsertComment);
widgets.put(VI_JOIN, this::viJoin);
widgets.put(VI_KILL_LINE, this::viKillWholeLine);
widgets.put(VI_MATCH_BRACKET, this::viMatchBracket);
widgets.put(VI_OPEN_LINE_ABOVE, this::viOpenLineAbove);
Expand Down Expand Up @@ -4879,6 +4891,7 @@ public KeyMap<Binding> emacs() {
bind(emacs, BACKWARD_DELETE_CHAR, del());
bind(emacs, VI_MATCH_BRACKET, translate("^X^B"));
bind(emacs, SEND_BREAK, translate("^X^G"));
bind(emacs, VI_JOIN, translate("^X^J"));
bind(emacs, OVERWRITE_MODE, translate("^X^O"));
bind(emacs, REDO, translate("^X^R"));
bind(emacs, UNDO, translate("^X^U"));
Expand Down Expand Up @@ -5025,6 +5038,7 @@ public KeyMap<Binding> viCmd() {
bind(vicmd, VI_FIND_PREV_CHAR, "F");
bind(vicmd, VI_FETCH_HISTORY, "G");
bind(vicmd, VI_INSERT_BOL, "I");
bind(vicmd, VI_JOIN, "J");
bind(vicmd, VI_REV_REPEAT_SEARCH, "N");
bind(vicmd, VI_OPEN_LINE_ABOVE, "O");
bind(vicmd, VI_PUT_AFTER, "P");
Expand Down
14 changes: 14 additions & 0 deletions reader/src/test/java/org/jline/reader/impl/ViMoveModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,20 @@ public void testo() throws Exception {
assertLine("great lakes brewery\ndog ", b, false);
}

@Test
public void testJ() throws Exception {
// J joins the current line with the following one
TestBuffer b = (new TestBuffer("bar"))
.escape()
.append("ofoo")
.escape()
.up()
.append("J")
.append("ii")
.enter();
assertLine("bari foo", b, false);
}

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

0 comments on commit cddb9ac

Please sign in to comment.