How can I run the same command in C# interactive in VS?
Usually CLI tools allow just to press the up arrow to get the previously typed command.
Is there a way to do something similar in C# interactive in Visual Studio? Pressing the up arrow just brings me one line up.
Is copy paster the only way to get the last typed command?
E.g. I typed Console.WriteLine(a);
, then I pressed Enter
. Now I want to execute the same Console.WriteLine(a);
again. So, I am pressing the up arrow, but instead of getting the Console.WriteLine(a);
typed in automatically, I am just going one line up.
> var a = "foo";
> Console.WriteLine(a);
foo
>
You probably want alt+up.
Typing #help
in the interactive window shows useful keyboard shortcuts:
> #help
Keyboard shortcuts:
Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line.
Ctrl-Enter Within the current submission, evaluate the current submission.
Within a previous submission, append the previous submission to the current submission.
Shift-Enter Insert a new line.
Escape Clear the current submission.
Alt-UpArrow Replace the current submission with a previous submission.
Alt-DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards).
Ctrl-Alt-UpArrow Replace the current submission with a previous submission beginning with the same text.
Ctrl-Alt-DownArrow Replace the current submission with a subsequent submission beginning with the same text (after having previously navigated backwards).
Ctrl-K, Ctrl-Enter Paste the selection at the end of interactive buffer, leave caret at the end of input.
Ctrl-E, Ctrl-Enter Paste and execute the selection before any pending input in the interactive buffer.
Ctrl-A First press, select the submission containing the cursor. Second press, select all text in the window.
REPL commands:
#cls, #clear Clears the contents of the editor window, leaving history and execution context intact.
#help Display help on specified command, or all available commands and key bindings if none specified.
#reset Reset the execution environment to the initial state and keep history, with the option to switch the runtime of the host process.
Script directives:
#r Add a metadata reference to specified assembly and all its dependencies, e.g. #r "myLib.dll".
#load Load specified script file and execute it, e.g. #load "myScript.csx".
>
You can change this by changing the keyboard shortcut for InteractiveConsole.HistoryPrevious.