Skip to content

Commit

Permalink
Support for the vi 'P' (put before) command, fixes #82
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jan 3, 2017
1 parent cddb9ac commit c9768fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 15 additions & 1 deletion reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2960,6 +2960,19 @@ protected boolean viPutAfter() {
return true;
}

protected boolean viPutBefore() {
if (yankBuffer.length () != 0) {
if (buf.cursor() > 0) {
buf.move(-1);
}
for (int i = 0; i < count; i++) {
putString(yankBuffer);
}
buf.move(-1);
}
return true;
}

protected boolean doLowercaseVersion() {
bindingReader.runMacro(getLastBinding().toLowerCase());
return true;
Expand Down Expand Up @@ -3201,6 +3214,7 @@ protected Map<String, Widget> builtinWidgets() {
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_PUT_BEFORE, this::viPutBefore);
widgets.put(VI_REPEAT_FIND, this::viRepeatFind);
widgets.put(VI_REPEAT_SEARCH, this::viRepeatSearch);
widgets.put(VI_REPLACE_CHARS, this::viReplaceChars);
Expand Down Expand Up @@ -5041,7 +5055,7 @@ public KeyMap<Binding> viCmd() {
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");
bind(vicmd, VI_PUT_BEFORE, "P");
bind(vicmd, VI_REPLACE, "R");
bind(vicmd, VI_KILL_LINE, "S");
bind(vicmd, VI_FIND_PREV_CHAR_SKIP, "T");
Expand Down
17 changes: 13 additions & 4 deletions reader/src/test/java/org/jline/reader/impl/ViMoveModeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,20 @@ public void testWordRight() throws Exception {
* Yank word right
*/
b = (new TestBuffer("big brown pickles"))
.escape()
.append("02yw$p")
.enter();
assertLine("big brown picklesbig brown ", b, false);
.escape()
.append("02yw$piz")
.enter();
assertLine("big brown picklesbig brownz ", b, false);

/*
* Put before
*/
b = (new TestBuffer("big brown pickles"))
.escape()
.append("02yw$Piz")
.enter();
assertLine("big brown picklebig brownz s", b, false);

/*
* Change word right
*/
Expand Down

0 comments on commit c9768fc

Please sign in to comment.