Skip to content

Commit 1d39641

Browse files
authored
vi-mode - Make 'dj' delete the current and next n logical lines (#1697)
1 parent 8b0cc85 commit 1d39641

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

PSReadLine/KeyBindings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function)
402402
case nameof(DeleteEndOfWord):
403403
case nameof(DeleteLine):
404404
case nameof(DeleteLineToFirstChar):
405+
case nameof(DeleteNextLines):
405406
case nameof(DeleteToEnd):
406407
case nameof(DeleteWord):
407408
case nameof(ForwardDeleteLine):

PSReadLine/KeyBindings.vi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ private void SetDefaultViBindings()
229229
{ Keys.ucG, MakeKeyHandler( DeleteEndOfBuffer, "DeleteEndOfBuffer") },
230230
{ Keys.ucE, MakeKeyHandler( ViDeleteEndOfGlob, "ViDeleteEndOfGlob") },
231231
{ Keys.H, MakeKeyHandler( BackwardDeleteChar, "BackwardDeleteChar") },
232+
{ Keys.J, MakeKeyHandler( DeleteNextLines, "DeleteNextLines") },
232233
{ Keys.L, MakeKeyHandler( DeleteChar, "DeleteChar") },
233234
{ Keys.Space, MakeKeyHandler( DeleteChar, "DeleteChar") },
234235
{ Keys._0, MakeKeyHandler( BackwardDeleteLine, "BackwardDeleteLine") },

PSReadLine/PSReadLineResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,7 @@ Or not saving history with:
805805
<data name="DeleteEndOfBufferDescription" xml:space="preserve">
806806
<value>Delete the current logical line and up to the end of the multiline buffer</value>
807807
</data>
808+
<data name="DeleteNextLinesDescription" xml:space="preserve">
809+
<value>Deletes the current and next n logical lines in a multiline buffer</value>
810+
</data>
808811
</root>

PSReadLine/ReadLine.vi.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,17 @@ public static void DeleteEndOfBuffer(ConsoleKeyInfo? key = null, object arg = nu
816816
_singleton.Render();
817817
}
818818

819+
/// <summary>
820+
/// Deletes the current and next n logical lines.
821+
/// </summary>
822+
private static void DeleteNextLines(ConsoleKeyInfo? key = null, object arg = null)
823+
{
824+
if (TryGetArgAsInt(arg, out int requestedLineCount, 1))
825+
{
826+
DeleteLine(key, requestedLineCount + 1);
827+
}
828+
}
829+
819830
/// <summary>
820831
/// Deletes the previous word.
821832
/// </summary>

test/BasicEditingTest.VI.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,24 @@ public void ViDeleteToEnd()
509509
));
510510
}
511511

512+
[SkippableFact]
513+
public void ViDeleteNextLines()
514+
{
515+
TestSetup(KeyMode.Vi);
516+
517+
int continuationPrefixLength = PSConsoleReadLineOptions.DefaultContinuationPrompt.Length;
518+
519+
Test("\"\n\"", Keys(
520+
 _.DQuote, _.Enter,
521+
"one", _.Enter,
522+
"two", _.Enter,
523+
"three", _.Enter,
524+
_.DQuote, _.Escape,
525+
"kkkl", // go to the 'ne' portion of "one"
526+
"2dj", CheckThat(() => AssertCursorLeftIs(continuationPrefixLength + 0))
527+
));
528+
}
529+
512530
[SkippableFact]
513531
public void ViGlobDelete()
514532
{

0 commit comments

Comments
 (0)