Skip to content

Commit a3e9172

Browse files
springcompdaxian-dbw
authored andcommitted
Make 'y0' yank up to the start of the logical line in VI mode. (#1167)
1 parent 06aec2c commit a3e9172

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

PSReadLine/YankPaste.vi.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,12 @@ public static void ViYankEndOfGlob(ConsoleKeyInfo? key = null, object arg = null
251251
/// </summary>
252252
public static void ViYankBeginningOfLine(ConsoleKeyInfo? key = null, object arg = null)
253253
{
254-
int length = _singleton._current;
254+
var start = GetBeginningOfLinePos(_singleton._current);
255+
var length = _singleton._current - start;
255256
if (length > 0)
256257
{
257-
_singleton.SaveToClipboard(0, length);
258+
_clipboard.Record(_singleton._buffer, start, length);
259+
_singleton.MoveCursor(start);
258260
}
259261
}
260262

test/YankPasteTest.VI.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,23 @@ public void ViPasteAfterYankBeginningOfLine()
324324
{
325325
TestSetup(KeyMode.Vi);
326326

327+
var continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
328+
327329
Test("012", Keys(
328330
"012", _.Escape,
329-
"y0P", CheckThat(() => AssertLineIs("01012")), CheckThat(() => AssertCursorLeftIs(3)),
331+
"y0P", CheckThat(() => AssertLineIs("01012")), CheckThat(() => AssertCursorLeftIs(1)),
330332
"u"
331333
));
332334

333-
Test(" 123 ", Keys(
334-
" 123 ", _.Escape,
335-
"y0P", CheckThat(() => AssertLineIs(" 123 123 ")), CheckThat(() => AssertCursorLeftIs(9)),
336-
"u"
335+
Test("\"\nHello\n World!\n\"", Keys(
336+
_.DQuote, _.Enter,
337+
"Hello", _.Enter,
338+
" World!", _.Enter,
339+
_.DQuote, _.Escape,
340+
_.k, "5l", // move the cursor to the 'd' character of "World!"
341+
"y0", CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0)),
342+
"P", CheckThat(() => AssertLineIs("\"\nHello\n Worl World!\n\"")), CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 4)),
343+
"u", CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
337344
));
338345
}
339346

0 commit comments

Comments
 (0)